Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[build]
command = "make ci-build"

[context.deploy-preview]
command = "make ci-build"
Comment on lines +1 to +5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why weren't these required before?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we configured it in the UI, now that we have more involved logic, we use a file to define how to interact with Netlify


[[plugins]]
package = "./plugins/netlify-plugin-docforge-cache"

[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
64 changes: 64 additions & 0 deletions plugins/netlify-plugin-docforge-cache/index.js
Original file line number Diff line number Diff line change
@@ -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.');
}
};
1 change: 1 addition & 0 deletions plugins/netlify-plugin-docforge-cache/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: netlify-plugin-docforge-cache