From d3e0cb176c3ff1fca7eb25c81580bd44b039b2e9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Chernyshev <81693471+slaveeks@users.noreply.github.com> Date: Tue, 13 Dec 2022 15:19:50 +0300 Subject: [PATCH 1/9] Added enable parameter for rendering index page (#289) --- package.json | 2 +- src/backend/build-static.ts | 5 ++++- src/backend/utils/appConfig.ts | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c9ff0c8..fd53502 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "v2.0.0-rc.4", + "version": "v2.2.0-rc.1", "type": "module", "bin": { "codex.docs": "dist/backend/app.js" diff --git a/src/backend/build-static.ts b/src/backend/build-static.ts index d0691e0..d8d4538 100644 --- a/src/backend/build-static.ts +++ b/src/backend/build-static.ts @@ -111,7 +111,10 @@ export default async function buildStatic(): Promise { await renderPage(page); } - await renderIndexPage(config.indexPageUri); + // Check if index page is enabled + if (config.indexPage.enabled) { + await renderIndexPage(config.indexPage.uri); + } console.log('Static files built'); console.log('Copy public directory'); diff --git a/src/backend/utils/appConfig.ts b/src/backend/utils/appConfig.ts index c824d49..8f853c6 100644 --- a/src/backend/utils/appConfig.ts +++ b/src/backend/utils/appConfig.ts @@ -90,7 +90,10 @@ const FrontendConfig = z.object({ */ const StaticBuildConfig = z.object({ outputDir: z.string(), // Output directory for static build - indexPageUri: z.string(), // URI for index page to render + indexPage: z.object({ + enabled: z.boolean(), // Is index page enabled + uri: z.string(), // Index page uri + }), }); export type StaticBuildConfig = z.infer; From f78b9ecff5f24fb871d01052ac563df50b837b70 Mon Sep 17 00:00:00 2001 From: Vyacheslav Chernyshev <81693471+slaveeks@users.noreply.github.com> Date: Tue, 27 Dec 2022 16:10:18 +0300 Subject: [PATCH 2/9] Fixed copy button path in header.twig, code.twig (#290) * Fixed copy button path in header.twig * Fixed path of copy button in code.twig, updated version * add more logs * Added overwrite property * update version Co-authored-by: Nikita Melnikov --- package.json | 2 +- src/backend/build-static.ts | 19 ++++++++++++++++--- src/backend/utils/appConfig.ts | 1 + src/backend/views/pages/blocks/code.twig | 2 +- src/backend/views/pages/blocks/header.twig | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index fd53502..490b138 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "v2.2.0-rc.1", + "version": "v2.2.0-rc.11", "type": "module", "bin": { "codex.docs": "dist/backend/app.js" diff --git a/src/backend/build-static.ts b/src/backend/build-static.ts index d8d4538..2b17fa4 100644 --- a/src/backend/build-static.ts +++ b/src/backend/build-static.ts @@ -45,8 +45,10 @@ export default async function buildStatic(): Promise { }); } - console.log('Removing old static files'); - await fse.remove(distPath); + if (config.overwrite) { + console.log('Removing old static files'); + await fse.remove(distPath); + } console.log('Building static files'); const pagesOrder = await PagesOrder.getAll(); @@ -118,11 +120,22 @@ export default async function buildStatic(): Promise { console.log('Static files built'); console.log('Copy public directory'); - await fse.copy(path.resolve(dirname, '../../public'), distPath); + 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') { console.log('Copy uploads directory'); await fse.copy(path.resolve(cwd, appConfig.uploads.local.path), path.resolve(distPath, 'uploads')); + console.log('Uploads directory copied'); } } diff --git a/src/backend/utils/appConfig.ts b/src/backend/utils/appConfig.ts index 8f853c6..8d3e60e 100644 --- a/src/backend/utils/appConfig.ts +++ b/src/backend/utils/appConfig.ts @@ -90,6 +90,7 @@ const FrontendConfig = z.object({ */ const StaticBuildConfig = z.object({ outputDir: z.string(), // Output directory for static build + overwrite: z.boolean().optional().default(true), indexPage: z.object({ enabled: z.boolean(), // Is index page enabled uri: z.string(), // Index page uri diff --git a/src/backend/views/pages/blocks/code.twig b/src/backend/views/pages/blocks/code.twig index 2402cb5..9ed997e 100644 --- a/src/backend/views/pages/blocks/code.twig +++ b/src/backend/views/pages/blocks/code.twig @@ -3,7 +3,7 @@
{{ code | escape }}
{% - include 'components/copy-button.twig' with { + include '../../components/copy-button.twig' with { ariaLabel: 'Copy Code to Clipboard', class: 'block-code__copy-button', textToCopy: code | escape, diff --git a/src/backend/views/pages/blocks/header.twig b/src/backend/views/pages/blocks/header.twig index e2e0403..d854dd9 100644 --- a/src/backend/views/pages/blocks/header.twig +++ b/src/backend/views/pages/blocks/header.twig @@ -1,6 +1,6 @@ {% - include 'components/copy-button.twig' with { + include '../../components/copy-button.twig' with { ariaLabel: 'Copy Link to the ' ~ text, class: 'block-header__copy-button', textToCopy: '#' ~ text | urlify, From 7f51a72bcbccdc1f2ddb5f0818604f247f6c338a Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Fri, 26 Apr 2024 13:47:43 +0300 Subject: [PATCH 3/9] fix(ui): broken sidebar, table of content and header on linux (#315) * move squircle to only to active and hover states * fix hover * fix squircle in header * fix toc * rm redundant line --- src/frontend/styles/components/header.pcss | 5 ++++- src/frontend/styles/components/sidebar.pcss | 7 +++++-- src/frontend/styles/components/table-of-content.pcss | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/frontend/styles/components/header.pcss b/src/frontend/styles/components/header.pcss index 0b43e9e..3c62720 100644 --- a/src/frontend/styles/components/header.pcss +++ b/src/frontend/styles/components/header.pcss @@ -40,7 +40,10 @@ html { @media (--not-mobile) { padding: 4px 10px; - @apply --squircle; + + &:hover { + @apply --squircle; + } } &:hover { diff --git a/src/frontend/styles/components/sidebar.pcss b/src/frontend/styles/components/sidebar.pcss index 7ce04ca..04f6f83 100644 --- a/src/frontend/styles/components/sidebar.pcss +++ b/src/frontend/styles/components/sidebar.pcss @@ -182,13 +182,16 @@ transition-property: background-color; transition-duration: 0.1s; - @apply --squircle; - &--selected { border-radius: 8px; /* border using box-shadow which doesn't increase the height */ box-shadow: 0 0 0 2px rgba(147, 166, 233, 0.5) inset; } + + &--active, + &:hover { + @apply --squircle; + } } &__section-title > span, diff --git a/src/frontend/styles/components/table-of-content.pcss b/src/frontend/styles/components/table-of-content.pcss index ab3c921..a3f5674 100644 --- a/src/frontend/styles/components/table-of-content.pcss +++ b/src/frontend/styles/components/table-of-content.pcss @@ -31,7 +31,10 @@ gap: 2px; &-item { - @apply --squircle; + &:hover, + &--active { + @apply --squircle; + } &:hover { background-color: var(--color-link-hover); From a6391a3da0b092db371dcd91d2bd1f647117fc9a Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Fri, 26 Apr 2024 17:31:40 +0300 Subject: [PATCH 4/9] Update version to v2.2.1 in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 490b138..2ef08eb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "v2.2.0-rc.11", + "version": "v2.2.1", "type": "module", "bin": { "codex.docs": "dist/backend/app.js" From f8ba8abf19129104dec5827f66813e06190fe82e Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Fri, 26 Apr 2024 22:57:49 +0100 Subject: [PATCH 5/9] Static generation fixes (#292) * add error handler for creating dist folder * fix favicon in generated files * add option for generating pages inside separate folders * fix favicon problem --------- Co-authored-by: Peter Savchenko --- src/backend/build-static.ts | 63 +++++++++++++++++++++------- src/backend/utils/appConfig.ts | 5 ++- src/backend/utils/downloadFavicon.ts | 17 ++++---- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/backend/build-static.ts b/src/backend/build-static.ts index 2b17fa4..ca0894a 100644 --- a/src/backend/build-static.ts +++ b/src/backend/build-static.ts @@ -13,6 +13,7 @@ import fse from 'fs-extra'; import appConfig from './utils/appConfig.js'; import Aliases from './controllers/aliases.js'; import Pages from './controllers/pages.js'; +import { downloadFavicon } from './utils/downloadFavicon.js'; /** * Build static pages from database @@ -54,7 +55,33 @@ export default async function buildStatic(): Promise { const pagesOrder = await PagesOrder.getAll(); const allPages = await Page.getAll(); - await mkdirp(distPath); + try { + console.log('Create dist folder'); + await mkdirp(distPath); + } catch (e) { + console.log('Error while creating dist folder', e); + + 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 @@ -64,6 +91,11 @@ export default async function buildStatic(): Promise { */ async function renderPage(page: Page, isIndex?: boolean): Promise { console.log(`Rendering page ${page.uri}`); + const pageUri = page.uri; + + if (!pageUri) { + throw new Error('Page uri is not defined'); + } const pageParent = await page.getParent(); const pageId = page._id; @@ -74,16 +106,30 @@ export default async function buildStatic(): Promise { const previousPage = await PagesFlatArray.getPageBefore(pageId); const nextPage = await PagesFlatArray.getPageAfter(pageId); const menu = createMenuTree(parentIdOfRootPages, allPages, pagesOrder, 2); + const result = await renderTemplate('./views/pages/page.twig', { page, pageParent, previousPage, nextPage, menu, + favicon, config: appConfig.frontend, }); - const filename = (isIndex || page.uri === '') ? 'index.html' : `${page.uri}.html`; + let filename: string; + + if (isIndex) { + filename = 'index.html'; + } else if (config?.pagesInsideFolders) { // create folder for each page if pagesInsideFolders is true + const pagePath = path.resolve(distPath, pageUri); + + await mkdirp(pagePath); + + filename = path.resolve(pagePath, 'index.html'); + } else { + filename = `${page.uri}.html`; + } await fs.writeFile(path.resolve(distPath, filename), result); console.log(`Page ${page.uri} rendered`); @@ -119,19 +165,6 @@ export default async function buildStatic(): Promise { } 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') { console.log('Copy uploads directory'); await fse.copy(path.resolve(cwd, appConfig.uploads.local.path), path.resolve(distPath, 'uploads')); diff --git a/src/backend/utils/appConfig.ts b/src/backend/utils/appConfig.ts index 8d3e60e..34a5e61 100644 --- a/src/backend/utils/appConfig.ts +++ b/src/backend/utils/appConfig.ts @@ -90,7 +90,10 @@ const FrontendConfig = z.object({ */ const StaticBuildConfig = z.object({ outputDir: z.string(), // Output directory for static build - overwrite: z.boolean().optional().default(true), + overwrite: z.boolean().optional() // Overwrite output directory + .default(true), + pagesInsideFolders: z.boolean().optional() // Create separate folder for each page + .default(true), indexPage: z.object({ enabled: z.boolean(), // Is index page enabled uri: z.string(), // Index page uri diff --git a/src/backend/utils/downloadFavicon.ts b/src/backend/utils/downloadFavicon.ts index 73aa2c0..ed10cdb 100644 --- a/src/backend/utils/downloadFavicon.ts +++ b/src/backend/utils/downloadFavicon.ts @@ -1,5 +1,5 @@ import path from 'path'; -import fs from 'fs'; +import fs from 'fs/promises'; import fetch, { RequestInit } from 'node-fetch'; /** @@ -32,9 +32,10 @@ function checkIsUrl(str: string): boolean { * * @param destination - url or path of favicon * @param faviconFolder - folder to save favicon + * @param subRoute - subroute from which the favicon will be served * @returns { Promise } - Promise with data about favicon */ -export async function downloadFavicon(destination: string, faviconFolder: string): Promise { +export async function downloadFavicon(destination: string, faviconFolder: string, subRoute = '/favicon'): Promise { // Check of destination is empty if (!destination) { throw Error('Favicon destination is empty'); @@ -48,8 +49,10 @@ export async function downloadFavicon(destination: string, faviconFolder: string // Check if string is url if (!checkIsUrl(destination)) { + await fs.copyFile(destination, path.join(faviconFolder, filename)); + return { - destination: `/${filename}`, + destination: `${subRoute}/${filename}`, type: `image/${format}`, } as FaviconData; } @@ -72,14 +75,10 @@ export async function downloadFavicon(destination: string, faviconFolder: string const filePath = path.join(faviconFolder, `favicon.${format}`); // Save file - await fs.writeFile(filePath, fileData, (err) => { - if (err) { - console.log(err); - } - }); + await fs.writeFile(filePath, fileData); return { - destination: `/favicon/favicon.${format}`, + destination: `${subRoute}/favicon.${format}`, type: `image/${format}`, } as FaviconData; } From 481461de4fdc66fb3f6460faee7720db4a5574df Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 27 Apr 2024 22:37:59 +0300 Subject: [PATCH 6/9] Update version to 2.2.2 in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ef08eb..269a543 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "v2.2.1", + "version": "2.2.2", "type": "module", "bin": { "codex.docs": "dist/backend/app.js" From bb9d537fb9a18576c5bb1e1d7c8e7900f7f54e9e Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 27 Apr 2024 22:47:02 +0300 Subject: [PATCH 7/9] Add static rendering feature (#316) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 37e8573..9981afb 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ It's super easy to install and use. - 🤩 [Editor.js](https://editorjs.io/) ecosystem powered - 📂 Docs nesting — create any structure you need +— 💎 Static rendering - 📱 Nice look on Desktop and Mobile - 🔥 Beautiful page URLs. Human-readable and SEO-friendly. - 🦅 [Hawk](https://hawk.so/?from=docs-demo) is hunting. Errors tracking integrated From 453f7060508d4f106abe18d57d17adac646ebaf3 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 27 Apr 2024 22:51:53 +0300 Subject: [PATCH 8/9] fix linebreak in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9981afb..83a8f83 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It's super easy to install and use. - 🤩 [Editor.js](https://editorjs.io/) ecosystem powered - 📂 Docs nesting — create any structure you need -— 💎 Static rendering +- 💎 Static rendering - 📱 Nice look on Desktop and Mobile - 🔥 Beautiful page URLs. Human-readable and SEO-friendly. - 🦅 [Hawk](https://hawk.so/?from=docs-demo) is hunting. Errors tracking integrated From 6c4d4310a9e1397ced462fe83dd2f68fd6b33c9e Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Fri, 3 May 2024 13:30:53 +0300 Subject: [PATCH 9/9] 2.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 269a543..4e6ae91 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "2.2.2", + "version": "2.2.3", "type": "module", "bin": { "codex.docs": "dist/backend/app.js"