From c60cdf166dc780184c677b7b84ad4cf90c5178e6 Mon Sep 17 00:00:00 2001 From: deepanshkhurana Date: Sun, 22 Feb 2026 01:11:22 +0530 Subject: [PATCH] refactor: move generated files to public/generated/ --- .gitignore | 3 +- CHANGELOG.md | 6 ++ build/calculate-stats.ts | 4 +- build/ensure-defaults.ts | 7 +- build/generate-body-of-work.ts | 4 +- build/generate-rss.ts | 6 +- build/generate-sitemap.ts | 12 +-- build/index-pages.ts | 4 +- build/index-pieces.ts | 6 +- build/paginate-pieces.ts | 4 +- docsite/docusaurus.config.ts | 2 +- public/robots.txt | 3 + public/sitemap.xml | 87 ------------------- src/components/BookViewer/BookViewer.jsx | 6 +- .../HomepageViewer/HomepageViewer.jsx | 2 +- src/components/Navigation/Navigation.jsx | 6 +- src/components/Volumes/Volumes.jsx | 2 +- src/components/WordsWasted/WordsWasted.jsx | 2 +- src/utils/resolveContentPath.js | 6 +- 19 files changed, 45 insertions(+), 127 deletions(-) create mode 100644 public/robots.txt delete mode 100644 public/sitemap.xml diff --git a/.gitignore b/.gitignore index 51c214c..dad7be5 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,4 @@ dist-ssr *.sw? # Content and generated files -public/index/*json -public/feed* +public/generated/ diff --git a/CHANGELOG.md b/CHANGELOG.md index cdb3fab..8c0aa58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.9] - 2026-02-22 + +### Changed + +- Moved auto-generated files to `public/generated/` subdirectory for cleaner structure. + ## [1.2.8] - 2026-02-20 ### Fixed diff --git a/build/calculate-stats.ts b/build/calculate-stats.ts index d8a668b..e983174 100644 --- a/build/calculate-stats.ts +++ b/build/calculate-stats.ts @@ -6,8 +6,8 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const publicDir = path.join(__dirname, '..', 'public'); -const piecesPagesJsonPath = path.join(publicDir, 'index', 'pieces-pages.json'); -const statsJsonPath = path.join(publicDir, 'index', 'stats.json'); +const piecesPagesJsonPath = path.join(publicDir, 'generated', 'index', 'pieces-pages.json'); +const statsJsonPath = path.join(publicDir, 'generated', 'index', 'stats.json'); try { const piecesPagesData = JSON.parse(fs.readFileSync(piecesPagesJsonPath, 'utf-8')); diff --git a/build/ensure-defaults.ts b/build/ensure-defaults.ts index 424b0d3..df3b4ba 100644 --- a/build/ensure-defaults.ts +++ b/build/ensure-defaults.ts @@ -9,11 +9,12 @@ const contentDir = path.join(publicDir, 'content'); const introPath = path.join(contentDir, 'intro.md'); const piecesDir = path.join(contentDir, 'pieces'); const pagesDir = path.join(contentDir, 'pages'); -const indexDir = path.join(publicDir, 'index'); +const generatedDir = path.join(publicDir, 'generated'); +const indexDir = path.join(generatedDir, 'index'); console.log('\nChecking for missing content...\n'); -[contentDir, piecesDir, pagesDir, indexDir].forEach(dir => { +[contentDir, piecesDir, pagesDir, generatedDir, indexDir].forEach(dir => { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); console.warn(`WARNING: Directory missing: ${path.basename(dir)}/ — created`); @@ -71,7 +72,7 @@ const robotsPath = path.join(publicDir, 'robots.txt'); const siteUrl = config.site?.url?.replace(/\/+$/, '') || 'https://example.com'; const robotsContent = `User-agent: * Disallow: -Sitemap: ${siteUrl}/sitemap.xml +Sitemap: ${siteUrl}/generated/sitemap.xml `; fs.writeFileSync(robotsPath, robotsContent); console.log('Generated robots.txt'); diff --git a/build/generate-body-of-work.ts b/build/generate-body-of-work.ts index 5d23f18..5f08582 100644 --- a/build/generate-body-of-work.ts +++ b/build/generate-body-of-work.ts @@ -3,8 +3,8 @@ import path from 'path'; import yaml from 'js-yaml'; const publicDir = path.join(__dirname, '..', 'public'); -const piecesJsonPath = path.join(publicDir, 'index', 'pieces.json'); -const collectionsJsonPath = path.join(publicDir, 'index', 'pieces-collections.json'); +const piecesJsonPath = path.join(publicDir, 'generated', 'index', 'pieces.json'); +const collectionsJsonPath = path.join(publicDir, 'generated', 'index', 'pieces-collections.json'); const bodyOfWorkPath = path.join(publicDir, 'content', 'pages', 'body-of-work.md'); const configPath = path.join(publicDir, 'config.yaml'); diff --git a/build/generate-rss.ts b/build/generate-rss.ts index 3ea34dc..b683e3d 100644 --- a/build/generate-rss.ts +++ b/build/generate-rss.ts @@ -11,8 +11,8 @@ const __dirname = path.dirname(__filename); const publicDir = path.join(__dirname, '..', 'public'); const contentDir = path.join(publicDir, 'content', 'pieces'); const configPath = path.join(publicDir, 'config.yaml'); -const piecesJsonPath = path.join(publicDir, 'index', 'pieces.json'); -const rssPath = path.join(publicDir, 'feed.xml'); +const piecesJsonPath = path.join(publicDir, 'generated', 'index', 'pieces.json'); +const rssPath = path.join(publicDir, 'generated', 'feed.xml'); interface Piece { slug: string; @@ -77,7 +77,7 @@ interface FrontMatter { rssLines.push(''); rssLines.push(''); rssLines.push(` ${escapeXml(siteTitle)}`); - rssLines.push(` `); + rssLines.push(` `); rssLines.push(` ${baseUrl}/`); rssLines.push(` ${escapeXml(siteTagline)}`); rssLines.push(` ${buildDate}`); diff --git a/build/generate-sitemap.ts b/build/generate-sitemap.ts index 9bd9ddd..c4136c3 100644 --- a/build/generate-sitemap.ts +++ b/build/generate-sitemap.ts @@ -8,10 +8,10 @@ const __dirname = path.dirname(__filename); const publicDir = path.join(__dirname, '..', 'public'); const configPath = path.join(publicDir, 'config.yaml'); -const piecesJsonPath = path.join(publicDir, 'index', 'pieces.json'); -const pagesJsonPath = path.join(publicDir, 'index', 'pages.json'); -const collectionsJsonPath = path.join(publicDir, 'index', 'pieces-collections.json'); -const sitemapPath = path.join(publicDir, 'sitemap.xml'); +const piecesJsonPath = path.join(publicDir, 'generated', 'index', 'pieces.json'); +const pagesJsonPath = path.join(publicDir, 'generated', 'index', 'pages.json'); +const collectionsJsonPath = path.join(publicDir, 'generated', 'index', 'pieces-collections.json'); +const sitemapPath = path.join(publicDir, 'generated', 'sitemap.xml'); interface Piece { slug: string; @@ -47,7 +47,6 @@ interface Collection { sitemapLines.push(''); sitemapLines.push(''); - // Homepage sitemapLines.push(' '); sitemapLines.push(` ${baseUrl}/`); sitemapLines.push(` ${currentDate}`); @@ -55,7 +54,6 @@ interface Collection { sitemapLines.push(' 1.0'); sitemapLines.push(' '); - // Pages for (const page of pages) { sitemapLines.push(' '); sitemapLines.push(` ${baseUrl}/${page.slug}`); @@ -65,7 +63,6 @@ interface Collection { sitemapLines.push(' '); } - // Collections/Reader pages for (const collection of collections) { sitemapLines.push(' '); sitemapLines.push(` ${baseUrl}/reader/${encodeURIComponent(collection.name)}`); @@ -75,7 +72,6 @@ interface Collection { sitemapLines.push(' '); } - // Individual pieces for (const piece of pieces) { sitemapLines.push(' '); sitemapLines.push(` ${baseUrl}/${piece.slug}`); diff --git a/build/index-pages.ts b/build/index-pages.ts index 462cdad..011acc8 100644 --- a/build/index-pages.ts +++ b/build/index-pages.ts @@ -5,8 +5,8 @@ import yaml from 'js-yaml'; const publicDir = path.join(__dirname, '..', 'public'); const pagesPath = path.join(publicDir, 'content', 'pages'); -const indexPath = path.join(publicDir, 'index', 'pages.json'); -const errorsPath = path.join(publicDir, 'index', 'page-errors.json'); +const indexPath = path.join(publicDir, 'generated', 'index', 'pages.json'); +const errorsPath = path.join(publicDir, 'generated', 'index', 'page-errors.json'); const configPath = path.join(publicDir, 'config.yaml'); type Page = { diff --git a/build/index-pieces.ts b/build/index-pieces.ts index 62def2e..1c7c97c 100644 --- a/build/index-pieces.ts +++ b/build/index-pieces.ts @@ -5,9 +5,9 @@ import yaml from 'js-yaml'; const publicDir = path.join(__dirname, '..', 'public'); const piecesPath = path.join(publicDir, 'content', 'pieces'); -const piecesIndexPath = path.join(publicDir, 'index', 'pieces.json'); -const collectionsPath = path.join(publicDir, 'index', 'pieces-collections.json'); -const errorsPath = path.join(publicDir, 'index', 'pieces-errors.json'); +const piecesIndexPath = path.join(publicDir, 'generated', 'index', 'pieces.json'); +const collectionsPath = path.join(publicDir, 'generated', 'index', 'pieces-collections.json'); +const errorsPath = path.join(publicDir, 'generated', 'index', 'pieces-errors.json'); const configPath = path.join(publicDir, 'config.yaml'); type Piece = { diff --git a/build/paginate-pieces.ts b/build/paginate-pieces.ts index eb8b44f..edd653c 100644 --- a/build/paginate-pieces.ts +++ b/build/paginate-pieces.ts @@ -4,8 +4,8 @@ import fm from "front-matter"; const publicDir = path.join(__dirname, '..', 'public'); const piecesPath = path.join(publicDir, 'content', 'pieces'); -const pagesIndexPath = path.join(publicDir, 'index', 'pieces-pages.json'); -const piecesIndexPath = path.join(publicDir, 'index', 'pieces.json'); +const pagesIndexPath = path.join(publicDir, 'generated', 'index', 'pieces-pages.json'); +const piecesIndexPath = path.join(publicDir, 'generated', 'index', 'pieces.json'); const CHARS_PER_PAGE = 2200; diff --git a/docsite/docusaurus.config.ts b/docsite/docusaurus.config.ts index fb17b91..e5ede0a 100644 --- a/docsite/docusaurus.config.ts +++ b/docsite/docusaurus.config.ts @@ -123,7 +123,7 @@ const config: Config = { { type: 'html', position: 'right', - value: 'v1.2.8', + value: 'v1.2.9', }, { href: 'https://demo.ode.dimwit.me/', diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..8940ec9 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Disallow: +Sitemap: https://demo.ode.dimwit.me/generated/sitemap.xml diff --git a/public/sitemap.xml b/public/sitemap.xml deleted file mode 100644 index 4525784..0000000 --- a/public/sitemap.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - https://demo.ode.dimwit.me/ - 2025-12-27 - daily - 1.0 - - - https://demo.ode.dimwit.me/about - 2025-12-27 - weekly - 0.8 - - - https://demo.ode.dimwit.me/body-of-work - 2025-12-27 - weekly - 0.8 - - - https://demo.ode.dimwit.me/references - 2025-12-27 - weekly - 0.8 - - - https://demo.ode.dimwit.me/reach-out - 2025-12-27 - weekly - 0.8 - - - https://demo.ode.dimwit.me/reader/Essays - 2025-12-27 - weekly - 0.7 - - - https://demo.ode.dimwit.me/reader/Metamorphosis - 2025-12-27 - weekly - 0.7 - - - https://demo.ode.dimwit.me/why-i-write - 1945-01-01 - monthly - 0.6 - - - https://demo.ode.dimwit.me/the-mark-on-the-wall - 1917-01-01 - monthly - 0.6 - - - https://demo.ode.dimwit.me/metamorphosis-chapter-1 - 1915-01-01 - monthly - 0.6 - - - https://demo.ode.dimwit.me/metamorphosis-chapter-2 - 1915-01-01 - monthly - 0.6 - - - https://demo.ode.dimwit.me/metamorphosis-chapter-3 - 1915-01-01 - monthly - 0.6 - - - https://demo.ode.dimwit.me/self-reliance - 1841-05-25 - monthly - 0.6 - - - https://demo.ode.dimwit.me/on-the-pleasure-of-hating - 1826-01-01 - monthly - 0.6 - - \ No newline at end of file diff --git a/src/components/BookViewer/BookViewer.jsx b/src/components/BookViewer/BookViewer.jsx index d217ff2..d1cb7d9 100644 --- a/src/components/BookViewer/BookViewer.jsx +++ b/src/components/BookViewer/BookViewer.jsx @@ -24,9 +24,9 @@ function BookViewer() { setLoading(true); try { const [pagesRes, collectionsRes, piecesRes, configData] = await Promise.all([ - fetch('/index/pieces-pages.json'), - fetch('/index/pieces-collections.json'), - fetch('/index/pieces.json'), + fetch('/generated/index/pieces-pages.json'), + fetch('/generated/index/pieces-collections.json'), + fetch('/generated/index/pieces.json'), loadConfig() ]); diff --git a/src/components/HomepageViewer/HomepageViewer.jsx b/src/components/HomepageViewer/HomepageViewer.jsx index 78f15f3..1ef5eaf 100644 --- a/src/components/HomepageViewer/HomepageViewer.jsx +++ b/src/components/HomepageViewer/HomepageViewer.jsx @@ -37,7 +37,7 @@ function HomepageViewer({ siteTitle, siteTagline }) { setPageContent({ content, frontmatter }); if (contentPath.includes('/pieces/')) { - const piecesResponse = await fetch('/index/pieces.json'); + const piecesResponse = await fetch('/generated/index/pieces.json'); const pieces = await piecesResponse.json(); const slug = contentPath.split('/pieces/')[1].replace('.md', ''); const metadata = pieces.find(p => p.slug === slug); diff --git a/src/components/Navigation/Navigation.jsx b/src/components/Navigation/Navigation.jsx index 00af999..74be768 100644 --- a/src/components/Navigation/Navigation.jsx +++ b/src/components/Navigation/Navigation.jsx @@ -5,8 +5,8 @@ import { loadConfig } from '../../utils/loadConfig'; function Navigation() { - const pagesIndexPath = '/index/pages.json'; - const piecesIndexPath = '/index/pieces.json'; + const pagesIndexPath = '/generated/index/pages.json'; + const piecesIndexPath = '/generated/index/pieces.json'; const [pages, setPages] = React.useState([]); const [pieces, setPieces] = React.useState([]); const [config, setConfig] = React.useState(null); @@ -47,7 +47,7 @@ function Navigation() { - + {config?.ui?.labels?.rss || 'RSS'} diff --git a/src/components/Volumes/Volumes.jsx b/src/components/Volumes/Volumes.jsx index 355adf2..cd4cd8b 100644 --- a/src/components/Volumes/Volumes.jsx +++ b/src/components/Volumes/Volumes.jsx @@ -9,7 +9,7 @@ function Volumes() { useEffect(() => { Promise.all([ - fetch('/index/pieces-collections.json').then(r => r.json()), + fetch('/generated/index/pieces-collections.json').then(r => r.json()), loadConfig() ]) .then(([collectionsData, configData]) => { diff --git a/src/components/WordsWasted/WordsWasted.jsx b/src/components/WordsWasted/WordsWasted.jsx index cc1acb5..248146c 100644 --- a/src/components/WordsWasted/WordsWasted.jsx +++ b/src/components/WordsWasted/WordsWasted.jsx @@ -9,7 +9,7 @@ function WordsWasted() { useEffect(() => { Promise.all([ loadConfig(), - fetch('/index/stats.json').then(r => r.json()) + fetch('/generated/index/stats.json').then(r => r.json()) ]) .then(([configData, statsData]) => { setConfig(configData); diff --git a/src/utils/resolveContentPath.js b/src/utils/resolveContentPath.js index c1ef2c6..6fd86c5 100644 --- a/src/utils/resolveContentPath.js +++ b/src/utils/resolveContentPath.js @@ -3,7 +3,7 @@ import { loadConfig } from './loadConfig'; export async function resolveContentPath({ pathname }) { if (pathname === '/') { try { - const res = await fetch('/index/pieces.json'); + const res = await fetch('/generated/index/pieces.json'); const pieces = await res.json(); if (pieces && pieces.length > 0) { const mostRecent = pieces[0]; @@ -18,7 +18,7 @@ export async function resolveContentPath({ pathname }) { let isPage = false; let isPiece = false; try { - const pagesRes = await fetch('/index/pages.json'); + const pagesRes = await fetch('/generated/index/pages.json'); const pages = await pagesRes.json(); isPage = pages.some(page => page.slug === slug); } catch (error) { @@ -27,7 +27,7 @@ export async function resolveContentPath({ pathname }) { } if (!isPage) { try { - const piecesRes = await fetch('/index/pieces.json'); + const piecesRes = await fetch('/generated/index/pieces.json'); const pieces = await piecesRes.json(); isPiece = pieces.some(piece => piece.slug === slug); } catch (error) {