2024-04-24 18:04:24 -04:00
|
|
|
import { z } from "zod";
|
|
|
|
import { fromZodError } from 'zod-validation-error';
|
|
|
|
|
2023-11-10 17:41:13 -05:00
|
|
|
export default {
|
2023-01-23 17:35:14 -05:00
|
|
|
tags: [
|
|
|
|
"posts"
|
|
|
|
],
|
|
|
|
"layout": "layouts/post.njk",
|
2024-07-25 17:06:34 -04:00
|
|
|
|
|
|
|
// Draft blog posts, validate `draft` front matter
|
2024-04-24 18:04:24 -04:00
|
|
|
eleventyDataSchema: function(data) {
|
|
|
|
let result = z.object({
|
|
|
|
draft: z.boolean().or(z.undefined()),
|
|
|
|
}).safeParse(data);
|
|
|
|
|
|
|
|
if(result.error) {
|
|
|
|
throw fromZodError(result.error);
|
|
|
|
}
|
|
|
|
},
|
2024-07-25 17:06:34 -04:00
|
|
|
|
|
|
|
// Draft blog posts, exclude from builds and collections
|
2024-04-24 18:04:24 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-01-23 17:35:14 -05:00
|
|
|
};
|