mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-19 05:09:41 +02:00
fix favicon problem
This commit is contained in:
parent
c8a2b87b1c
commit
6e2cb1bf8f
3 changed files with 27 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "codex.docs",
|
"name": "codex.docs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"version": "v2.2.0-rc.13",
|
"version": "v2.2.0-rc.16",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"codex.docs": "dist/backend/app.js"
|
"codex.docs": "dist/backend/app.js"
|
||||||
|
|
|
@ -64,6 +64,24 @@ export default async function buildStatic(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Copy public directory');
|
||||||
|
const publicDir = path.resolve(dirname, '../../public');
|
||||||
|
|
||||||
|
console.log(`Copy from ${publicDir} to ${distPath}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fse.copy(publicDir, distPath);
|
||||||
|
console.log('Public directory copied');
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error while copying public directory');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const favicon = appConfig.favicon ? await downloadFavicon(appConfig.favicon, distPath, '') : {
|
||||||
|
destination: '/favicon.png',
|
||||||
|
type: 'image/png',
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders single page
|
* Renders single page
|
||||||
|
@ -88,10 +106,6 @@ export default async function buildStatic(): Promise<void> {
|
||||||
const previousPage = await PagesFlatArray.getPageBefore(pageId);
|
const previousPage = await PagesFlatArray.getPageBefore(pageId);
|
||||||
const nextPage = await PagesFlatArray.getPageAfter(pageId);
|
const nextPage = await PagesFlatArray.getPageAfter(pageId);
|
||||||
const menu = createMenuTree(parentIdOfRootPages, allPages, pagesOrder, 2);
|
const menu = createMenuTree(parentIdOfRootPages, allPages, pagesOrder, 2);
|
||||||
const favicon = appConfig.favicon ? await downloadFavicon(appConfig.favicon, distPath) : {
|
|
||||||
destination: '/favicon.png',
|
|
||||||
type: 'image/png',
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await renderTemplate('./views/pages/page.twig', {
|
const result = await renderTemplate('./views/pages/page.twig', {
|
||||||
page,
|
page,
|
||||||
|
@ -151,19 +165,6 @@ export default async function buildStatic(): Promise<void> {
|
||||||
}
|
}
|
||||||
console.log('Static files built');
|
console.log('Static files built');
|
||||||
|
|
||||||
console.log('Copy public directory');
|
|
||||||
const publicDir = path.resolve(dirname, '../../public');
|
|
||||||
|
|
||||||
console.log(`Copy from ${publicDir} to ${distPath}`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await fse.copy(publicDir, distPath);
|
|
||||||
console.log('Public directory copied');
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error while copying public directory');
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appConfig.uploads.driver === 'local') {
|
if (appConfig.uploads.driver === 'local') {
|
||||||
console.log('Copy uploads directory');
|
console.log('Copy uploads directory');
|
||||||
await fse.copy(path.resolve(cwd, appConfig.uploads.local.path), path.resolve(distPath, 'uploads'));
|
await fse.copy(path.resolve(cwd, appConfig.uploads.local.path), path.resolve(distPath, 'uploads'));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import fetch, { RequestInit } from 'node-fetch';
|
import fetch, { RequestInit } from 'node-fetch';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +32,10 @@ function checkIsUrl(str: string): boolean {
|
||||||
*
|
*
|
||||||
* @param destination - url or path of favicon
|
* @param destination - url or path of favicon
|
||||||
* @param faviconFolder - folder to save favicon
|
* @param faviconFolder - folder to save favicon
|
||||||
|
* @param subRoute - subroute from which the favicon will be served
|
||||||
* @returns { Promise<FaviconData> } - Promise with data about favicon
|
* @returns { Promise<FaviconData> } - Promise with data about favicon
|
||||||
*/
|
*/
|
||||||
export async function downloadFavicon(destination: string, faviconFolder: string): Promise<FaviconData> {
|
export async function downloadFavicon(destination: string, faviconFolder: string, subRoute = '/favicon'): Promise<FaviconData> {
|
||||||
// Check of destination is empty
|
// Check of destination is empty
|
||||||
if (!destination) {
|
if (!destination) {
|
||||||
throw Error('Favicon destination is empty');
|
throw Error('Favicon destination is empty');
|
||||||
|
@ -48,8 +49,10 @@ export async function downloadFavicon(destination: string, faviconFolder: string
|
||||||
|
|
||||||
// Check if string is url
|
// Check if string is url
|
||||||
if (!checkIsUrl(destination)) {
|
if (!checkIsUrl(destination)) {
|
||||||
|
await fs.copyFile(destination, path.join(faviconFolder, filename));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destination: `/${filename}`,
|
destination: `${subRoute}/${filename}`,
|
||||||
type: `image/${format}`,
|
type: `image/${format}`,
|
||||||
} as FaviconData;
|
} as FaviconData;
|
||||||
}
|
}
|
||||||
|
@ -72,14 +75,10 @@ export async function downloadFavicon(destination: string, faviconFolder: string
|
||||||
const filePath = path.join(faviconFolder, `favicon.${format}`);
|
const filePath = path.join(faviconFolder, `favicon.${format}`);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
await fs.writeFile(filePath, fileData, (err) => {
|
await fs.writeFile(filePath, fileData);
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destination: `/favicon/favicon.${format}`,
|
destination: `${subRoute}/favicon.${format}`,
|
||||||
type: `image/${format}`,
|
type: `image/${format}`,
|
||||||
} as FaviconData;
|
} as FaviconData;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue