1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

swap JS favicons lib for python favicons lib

This commit is contained in:
checktheroads
2020-07-27 00:41:21 -07:00
parent 6017f4cb6d
commit 34b1466dbe
6 changed files with 43 additions and 1390 deletions

View File

@@ -1,72 +0,0 @@
const fs = require("fs");
const favicons = require("favicons");
const tempy = require("tempy");
const defaultConfig = {
path: "/images/favicons",
appleStatusBarStyle: "black-translucent",
display: "standalone",
orientation: "any",
scope: "/",
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: true,
favicons: true,
firefox: true,
windows: true,
yandex: true
}
};
const handleError = err => {
if (err) {
if (err.message) {
console.error(err.message);
return;
}
console.error(err);
return;
}
return;
};
const writeHtml = (path, data) => {
fs.writeFile(path, data, handleError);
return;
};
const writeFiles = (basePath, files) => {
files.forEach(attrs => {
fs.writeFile(`${basePath}/${attrs.name}`, attrs.contents, handleError);
});
return;
};
const generateFavicons = (config, appPath) => {
const htmlFile = tempy.file({ extension: "json" });
const callback = (err, response) => {
handleError(err);
writeFiles(`${appPath}/static/images/favicons`, response.images);
writeFiles(`${appPath}/static/images/favicons`, response.files);
writeHtml(htmlFile, JSON.stringify(response.html));
return;
};
favicons(
config.web.logo.favicon,
{
appName: config.site_title,
appDescription: config.site_description,
lang: config.language || "en-US",
background: config.web.theme.colors.white,
theme_color: config.web.theme.colors.primary,
...defaultConfig
},
callback
);
return htmlFile;
};
module.exports = generateFavicons;

View File

@@ -2,12 +2,6 @@ const aliases = require("./.alias");
const envVars = require("/tmp/hyperglass.env.json");
const { configFile } = envVars;
const config = require(String(configFile));
const generateFavicons = require("./generateFavicons");
const faviconHtmlFile = generateFavicons(
config._HYPERGLASS_CONFIG_,
config._HYPERGLASS_APP_PATH_
);
module.exports = {
webpack(config) {
@@ -23,6 +17,6 @@ module.exports = {
_NODE_ENV_: config.NODE_ENV,
_HYPERGLASS_URL_: config._HYPERGLASS_URL_,
_HYPERGLASS_CONFIG_: config._HYPERGLASS_CONFIG_,
_FAVICON_HTML_FILE_: faviconHtmlFile
_HYPERGLASS_FAVICONS_: config._HYPERGLASS_FAVICONS_
}
};

View File

@@ -24,9 +24,7 @@
"chroma-js": "^2.1.0",
"dayjs": "^1.8.25",
"emotion-theming": "^10.0.27",
"favicons": "^6.1.0",
"framer-motion": "^1.10.0",
"html-to-react": "^1.4.3",
"lodash": "^4.17.15",
"next": "^9.4",
"react": "^16.13.1",

View File

@@ -1,9 +1,6 @@
import * as React from "react";
import { createElement } from "react";
import Head from "next/head";
import dynamic from "next/dynamic";
import fs from "fs";
import { Parser } from "html-to-react";
import Meta from "~/components/Meta";
import Loading from "~/components/Loading";
const LookingGlass = dynamic(() => import("~/components/LookingGlass"), {
@@ -14,9 +11,9 @@ const Index = ({ faviconComponents }) => {
return (
<>
<Head>
{faviconComponents.map((comp, i) =>
createElement(comp.type, { key: i, ...comp.props })
)}
{faviconComponents.map(({ rel, href, type }, i) => (
<link rel={rel} href={href} type={type} key={i} />
))}
</Head>
<Meta />
<LookingGlass />
@@ -25,11 +22,10 @@ const Index = ({ faviconComponents }) => {
};
export async function getStaticProps(context) {
const htmlToReact = new Parser();
const lines = fs.readFileSync(process.env._FAVICON_HTML_FILE_, "utf-8");
const components = JSON.parse(lines).map(elem => {
const comp = htmlToReact.parse(elem);
return { type: comp.type, props: comp.props };
const components = process.env._HYPERGLASS_FAVICONS_.map(icon => {
const { image_format, dimensions, prefix, rel } = icon;
const src = `/images/favicons/${prefix}-${dimensions[0]}x${dimensions[1]}.${image_format}`;
return { rel, href: src, type: `image/${image_format}` };
});
return {
props: {

1320
hyperglass/ui/yarn.lock vendored

File diff suppressed because it is too large Load Diff