Drastically simplify the drafts workflow
This commit is contained in:
parent
1ad494cfd2
commit
31235827fc
13
_data/eleventyDataSchema.js
Normal file
13
_data/eleventyDataSchema.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { fromZodError } from 'zod-validation-error';
|
||||
|
||||
export default function(data) {
|
||||
// Draft content, validate `draft` front matter
|
||||
let result = z.object({
|
||||
draft: z.boolean().or(z.undefined()),
|
||||
}).safeParse(data);
|
||||
|
||||
if(result.error) {
|
||||
throw fromZodError(result.error);
|
||||
}
|
||||
}
|
@ -1,40 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { fromZodError } from 'zod-validation-error';
|
||||
|
||||
export default {
|
||||
tags: [
|
||||
"posts"
|
||||
],
|
||||
"layout": "layouts/post.njk",
|
||||
|
||||
// Draft blog posts, validate `draft` front matter
|
||||
eleventyDataSchema: function(data) {
|
||||
let result = z.object({
|
||||
draft: z.boolean().or(z.undefined()),
|
||||
}).safeParse(data);
|
||||
|
||||
if(result.error) {
|
||||
throw fromZodError(result.error);
|
||||
}
|
||||
},
|
||||
|
||||
// Draft blog posts, exclude from builds and collections
|
||||
eleventyComputed: {
|
||||
permalink: (data) => {
|
||||
// Always skip during non-watch/serve builds
|
||||
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return data.permalink;
|
||||
},
|
||||
eleventyExcludeFromCollections: (data) => {
|
||||
// Always exclude from non-watch/serve builds
|
||||
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return data.eleventyExcludeFromCollections;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -8,6 +8,13 @@ import pluginFilters from "./_config/filters.js";
|
||||
|
||||
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
||||
export default async function(eleventyConfig) {
|
||||
// Drafts, see also _data/eleventyDataSchema.js
|
||||
eleventyConfig.addPreprocessor("drafts", "*", (data, content) => {
|
||||
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Copy the contents of the `public` folder to the output folder
|
||||
// For example, `./public/css/` ends up in `_site/css/`
|
||||
eleventyConfig
|
||||
|
Loading…
Reference in New Issue
Block a user