add drafts functionality
This commit is contained in:
parent
e0b6131921
commit
84b0ea9d92
4 changed files with 41 additions and 5 deletions
|
|
@ -45,6 +45,7 @@ export default async function (eleventyConfig) {
|
||||||
eleventyConfig.addPlugin(plugins.htmlConfig);
|
eleventyConfig.addPlugin(plugins.htmlConfig);
|
||||||
eleventyConfig.addPlugin(plugins.cssConfig);
|
eleventyConfig.addPlugin(plugins.cssConfig);
|
||||||
eleventyConfig.addPlugin(plugins.jsConfig);
|
eleventyConfig.addPlugin(plugins.jsConfig);
|
||||||
|
eleventyConfig.addPlugin(plugins.drafts);
|
||||||
|
|
||||||
eleventyConfig.addPlugin(plugins.EleventyRenderPlugin);
|
eleventyConfig.addPlugin(plugins.EleventyRenderPlugin);
|
||||||
eleventyConfig.addPlugin(plugins.rss);
|
eleventyConfig.addPlugin(plugins.rss);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import webc from '@11ty/eleventy-plugin-webc';
|
||||||
|
|
||||||
// custom
|
// custom
|
||||||
import {markdownLib} from './plugins/markdown.js';
|
import {markdownLib} from './plugins/markdown.js';
|
||||||
|
import {drafts} from './plugins/drafts.js';
|
||||||
|
|
||||||
// Custom transforms
|
// Custom transforms
|
||||||
import {htmlConfig} from './plugins/html-config.js';
|
import {htmlConfig} from './plugins/html-config.js';
|
||||||
|
|
@ -20,6 +21,7 @@ export default {
|
||||||
syntaxHighlight,
|
syntaxHighlight,
|
||||||
webc,
|
webc,
|
||||||
markdownLib,
|
markdownLib,
|
||||||
|
drafts,
|
||||||
htmlConfig,
|
htmlConfig,
|
||||||
cssConfig,
|
cssConfig,
|
||||||
jsConfig
|
jsConfig
|
||||||
|
|
|
||||||
30
src/_config/plugins/drafts.js
Normal file
30
src/_config/plugins/drafts.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
export const drafts = eleventyConfig => {
|
||||||
|
eleventyConfig.addGlobalData('eleventyComputed.permalink', function () {
|
||||||
|
return data => {
|
||||||
|
// Always skip during non-watch/serve builds
|
||||||
|
if (data.draft && !process.env.BUILD_DRAFTS) {
|
||||||
|
return false; // Ensure templates that use this handle it correctly
|
||||||
|
}
|
||||||
|
return data.permalink;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// When `eleventyExcludeFromCollections` is true, the file is not included in any collections
|
||||||
|
eleventyConfig.addGlobalData('eleventyComputed.eleventyExcludeFromCollections', function () {
|
||||||
|
return data => {
|
||||||
|
// Always exclude from non-watch/serve builds
|
||||||
|
if (data.draft && !process.env.BUILD_DRAFTS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.eleventyExcludeFromCollections ?? false;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
eleventyConfig.on('eleventy.before', ({runMode}) => {
|
||||||
|
// Set the environment variable
|
||||||
|
if (runMode === 'serve' || runMode === 'watch') {
|
||||||
|
process.env.BUILD_DRAFTS = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -9,12 +9,15 @@
|
||||||
export function getLinkActiveState(itemUrl, pageUrl) {
|
export function getLinkActiveState(itemUrl, pageUrl) {
|
||||||
let response = '';
|
let response = '';
|
||||||
|
|
||||||
if (itemUrl === pageUrl) {
|
// Ensure pageUrl is a string before proceeding
|
||||||
response = ' aria-current="page"';
|
if (typeof pageUrl === 'string') {
|
||||||
}
|
if (itemUrl === pageUrl) {
|
||||||
|
response = ' aria-current="page"';
|
||||||
|
}
|
||||||
|
|
||||||
if (itemUrl.length > 1 && pageUrl.indexOf(itemUrl.replace('/page-0/', '')) === 0) {
|
if (itemUrl.length > 1 && pageUrl.startsWith(itemUrl.replace('/page-0/', ''))) {
|
||||||
response += 'data-state="active"';
|
response += ' data-state="active"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue