diff --git a/.gitignore b/.gitignore index 8281b795e..ad5b5c76b 100755 --- a/.gitignore +++ b/.gitignore @@ -107,6 +107,9 @@ dist # Docforge binary directory /bin +# Docforge HTTP cache (persisted by Netlify plugin between builds) +.docforge-cache + # vuepress build output .vuepress/dist diff --git a/Makefile b/Makefile index b6226ca22..b2e21b5d0 100644 --- a/Makefile +++ b/Makefile @@ -152,7 +152,7 @@ build: ## Build the documentation site docforge-ci: docforge-download ## Run docforge in CI mode (non-interactive) @echo "Running docforge (CI)..." @export DOCFORGE_CONFIG=.docforge/config.yaml && \ - ./bin/docforge + ./bin/docforge --cache-dir ./.docforge-cache .PHONY: ci-build ci-build: docforge-ci install post-process build ## Run all steps for building in CI \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 52810d367..fe405a292 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,4 +1,13 @@ +[build] + command = "make ci-build" + +[context.deploy-preview] + command = "make ci-build" + +[[plugins]] + package = "./plugins/netlify-plugin-docforge-cache" + [[headers]] - for = "/*" - [headers.values] - X-Frame-Options = "DENY" + for = "/*" + [headers.values] + X-Frame-Options = "DENY" diff --git a/plugins/netlify-plugin-docforge-cache/index.js b/plugins/netlify-plugin-docforge-cache/index.js new file mode 100644 index 000000000..a86bb69c4 --- /dev/null +++ b/plugins/netlify-plugin-docforge-cache/index.js @@ -0,0 +1,64 @@ +import { readdir } from 'fs/promises'; +import { join } from 'path'; + +const CACHE_DIR = '.docforge-cache'; +const CACHE_TTL = 86400; + +async function collectDigests(baseDir) { + const digests = []; + + async function walk(dir) { + let entries; + try { + entries = await readdir(dir, { withFileTypes: true }); + } catch (err) { + if (err.code === 'ENOENT') return; + throw err; + } + for (const entry of entries) { + const fullPath = join(dir, entry.name); + if (entry.isDirectory()) { + await walk(fullPath); + } else if (entry.isFile() && entry.name.endsWith('.yaml')) { + digests.push(fullPath); + } + } + } + + await walk(baseDir); + return digests; +} + +export const onPreBuild = async function ({ utils }) { + if (process.env.CONTEXT === 'production') { + console.log('Production build — skipping docforge cache (always fresh).'); + return; + } + + const restored = await utils.cache.restore(CACHE_DIR); + if (restored) { + console.log('Docforge cache restored from previous build.'); + } else { + console.log('No docforge cache found — will be populated after this build.'); + } +}; + +export const onPostBuild = async function ({ utils }) { + if (process.env.CONTEXT === 'production') { + console.log('Production build — not saving docforge cache.'); + return; + } + + const digests = await collectDigests('.docforge'); + + const saved = await utils.cache.save(CACHE_DIR, { + ttl: CACHE_TTL, + digests, + }); + + if (saved) { + console.log(`Docforge cache saved (TTL: 24h, tracking ${digests.length} digest files).`); + } else { + console.log('Docforge cache directory not found — nothing to save.'); + } +}; diff --git a/plugins/netlify-plugin-docforge-cache/manifest.yml b/plugins/netlify-plugin-docforge-cache/manifest.yml new file mode 100644 index 000000000..a344a8f0f --- /dev/null +++ b/plugins/netlify-plugin-docforge-cache/manifest.yml @@ -0,0 +1 @@ +name: netlify-plugin-docforge-cache