mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
add favicon generation, closes #45
This commit is contained in:
@@ -21,8 +21,6 @@ export const HyperglassProvider = ({ config, children }) => {
|
||||
const value = useMemo(() => config, [config]);
|
||||
const userTheme = value && makeTheme(value.web.theme);
|
||||
const theme = value ? userTheme : defaultTheme;
|
||||
// console.log(value);
|
||||
// console.log(theme);
|
||||
return (
|
||||
<HyperglassContext.Provider value={value}>
|
||||
<ThemeProvider theme={theme}>
|
||||
|
72
hyperglass/ui/generateFavicons.js
Normal file
72
hyperglass/ui/generateFavicons.js
Normal file
@@ -0,0 +1,72 @@
|
||||
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/ui`, 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;
|
@@ -2,6 +2,12 @@ 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) {
|
||||
@@ -16,6 +22,7 @@ module.exports = {
|
||||
env: {
|
||||
_NODE_ENV_: config.NODE_ENV,
|
||||
_HYPERGLASS_URL_: config._HYPERGLASS_URL_,
|
||||
_HYPERGLASS_CONFIG_: config._HYPERGLASS_CONFIG_
|
||||
_HYPERGLASS_CONFIG_: config._HYPERGLASS_CONFIG_,
|
||||
_FAVICON_HTML_FILE_: faviconHtmlFile
|
||||
}
|
||||
};
|
||||
|
3
hyperglass/ui/package.json
vendored
3
hyperglass/ui/package.json
vendored
@@ -24,7 +24,9 @@
|
||||
"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.3.1",
|
||||
"react": "^16.13.1",
|
||||
@@ -39,6 +41,7 @@
|
||||
"react-textfit": "^1.1.0",
|
||||
"string-format": "^2.0.0",
|
||||
"styled-system": "^5.1.5",
|
||||
"tempy": "^0.5.0",
|
||||
"use-media": "^1.4.0",
|
||||
"yup": "^0.28.3"
|
||||
},
|
||||
|
@@ -1,16 +1,41 @@
|
||||
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"), {
|
||||
loading: Loading
|
||||
});
|
||||
|
||||
const Index = () => (
|
||||
<>
|
||||
<Meta />
|
||||
<LookingGlass />
|
||||
</>
|
||||
);
|
||||
const Index = ({ faviconComponents }) => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
{faviconComponents.map((comp, i) =>
|
||||
createElement(comp.type, { key: i, ...comp.props })
|
||||
)}
|
||||
</Head>
|
||||
<Meta />
|
||||
<LookingGlass />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
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 };
|
||||
});
|
||||
return {
|
||||
props: {
|
||||
faviconComponents: components
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Index;
|
||||
|
3844
hyperglass/ui/yarn.lock
vendored
3844
hyperglass/ui/yarn.lock
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user