{{ item.data.title }}
{{ item.data.description }}
{{ description }}
{{ item.data.description }}
const fs = require('fs');
const path = require('path');
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addFilter("date", function(date, format = "yyyy-MM-dd") {
if (date === "now") {
date = new Date();
} else if (!(date instanceof Date)) {
date = new Date(date);
}
if (isNaN(date.getTime())) {
return "";
}
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
switch (format) {
case "yyyy":
return year.toString();
default:
return `${year}-${month}-${day}`;
}
});
eleventyConfig.addFilter("filterByDiscipline", function(collection, discipline) {
if (!collection) return [];
return collection.filter(item => item.data.discipline === discipline);
});
const disciplines = ['development', 'project-management', 'sales-marketing', 'content-strategy', 'design', 'quality-assurance'];
const contentTypes = ['prompts', 'rules', 'project-configs', 'workflow-states', 'resources'];
contentTypes.forEach(type => {
eleventyConfig.addCollection(type, function(collection) {
return collection.getFilteredByGlob(
disciplines.map(discipline => `${discipline}/${type}/**/*.md`)
).map(item => {
if (process.env.GITHUB_ACTIONS && !item.url.startsWith('/prompt_library')) {
item.url = `/prompt_library${item.url}`;
}
return item;
});
});
});
eleventyConfig.addCollection("searchIndex", async function(collection) {
const items = collection.getAll().filter(item => item.template.inputPath.endsWith('.md'));
const searchIndex = [];
for (const item of items) {
const content = await item.template.read();
const url = process.env.GITHUB_ACTIONS && !item.url.startsWith('/prompt_library')
? `/prompt_library${item.url}`
: item.url;
searchIndex.push({
title: item.data.title || '',
description: item.data.description || '',
content: content || '',
url: url,
discipline: item.data.discipline || '',
contentType: item.data.contentType || '',
tags: item.data.tags || [],
date: item.data.date || new Date().toISOString()
});
}
const outputPath = path.join(__dirname, '_site', 'search-index.json');
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(outputPath, JSON.stringify(searchIndex));
return searchIndex;
});
const baseUrl = process.env.GITHUB_ACTIONS ? "/prompt_library" : "";
eleventyConfig.addGlobalData("baseUrl", baseUrl);
eleventyConfig.addFilter("fullUrl", function(url) {
if (url.startsWith(baseUrl)) {
return url;
}
return `${baseUrl}${url}`;
});
eleventyConfig.addNunjucksFilter("hasContent", function(discipline, contentType) {
const collections = this.ctx.collections;
const logPrefix = "[HAS_CONTENT_NJK_DEBUG]";
console.log(`${logPrefix} Checking filter for: discipline='${discipline}', contentType='${contentType}'`);
const collectionName = contentType.toLowerCase().replace(/\s+/g, '-');
if (!collections || !collections[collectionName]) {
console.log(`${logPrefix} Collection not found for '${collectionName}'. Returning false.`);
return false;
}
const collectionItems = collections[collectionName];
console.log(`${logPrefix} Found collection '${collectionName}' with ${collectionItems.length} items.`);
const hasContent = collectionItems.some(item => {
const itemDiscipline = item.data.discipline;
const match = typeof itemDiscipline === 'string' && typeof discipline === 'string' && itemDiscipline.toLowerCase() === discipline.toLowerCase();
console.log(`${logPrefix} Comparing item discipline '${itemDiscipline}' === filter discipline '${discipline}': ${match}`);
return match;
});
console.log(`${logPrefix} Final result for ${discipline}/${contentType}: ${hasContent}`);
return hasContent;
});
eleventyConfig.addCollection('recentlyAdded', function(collection) {
const types = ['prompts', 'rules', 'project-configs', 'workflow-states', 'resources'];
let all = [];
types.forEach(type => {
all = all.concat(collection.getFilteredByGlob(
disciplines.map(discipline => `${discipline}/${type}/**/*.md`)
));
});
return all.sort((a, b) => new Date(b.date) - new Date(a.date));
});
return {
dir: {
input: ".",
output: "_site",
includes: "_includes",
layouts: "_layouts",
data: "_data"
},
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
pathPrefix: baseUrl
};
};
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
function getMarkdownFiles(dir) {
let results = [];
const items = fs.readdirSync(dir);
for (const item of items) {
const fullPath = path.join(dir, item);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
results = results.concat(getMarkdownFiles(fullPath));
} else if (item.endsWith('.md')) {
results.push(fullPath);
}
}
return results;
}
function createSearchIndex() {
const contentDirs = [
'development',
'project-management',
'sales-marketing',
'content-strategy',
'design',
'quality-assurance'
];
const searchIndex = [];
for (const dir of contentDirs) {
if (!fs.existsSync(dir)) continue;
const files = getMarkdownFiles(dir);
for (const file of files) {
const content = fs.readFileSync(file, 'utf8');
const { data, content: markdown } = matter(content);
const relativePath = path.relative(process.cwd(), file);
const url = '/' + relativePath.replace(/\\/g, '/').replace(/\.md$/, '/');
searchIndex.push({
title: data.title || '',
description: data.description || '',
content: markdown,
url: url,
discipline: data.discipline || dir,
contentType: data.contentType || '',
tags: data.tags || [],
date: data.date || new Date().toISOString()
});
}
}
return searchIndex;
}
module.exports = createSearchIndex;
const STORAGE_KEY = 'theme-preference';
const DARK_CLASS = 'dark-theme';
function getColorPreference() {
if (localStorage.getItem(STORAGE_KEY)) {
return localStorage.getItem(STORAGE_KEY);
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
function setTheme(theme) {
localStorage.setItem(STORAGE_KEY, theme);
reflectTheme(theme);
}
function reflectTheme(theme) {
document.documentElement.classList.toggle(DARK_CLASS, theme === 'dark');
document.querySelector('#theme-toggle')?.setAttribute('aria-label',
theme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'
);
}
function toggleTheme() {
const currentTheme = getColorPreference();
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
}
function initializeTheme() {
const theme = getColorPreference();
setTheme(theme);
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', ({ matches }) => {
if (!localStorage.getItem(STORAGE_KEY)) {
setTheme(matches ? 'dark' : 'light');
}
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeTheme);
} else {
initializeTheme();
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
document.addEventListener('DOMContentLoaded', function() {
const currentPath = window.location.pathname;
const navLinks = document.querySelectorAll('nav a');
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
});
document.addEventListener('DOMContentLoaded', function() {
let searchIndex = [];
const searchForm = document.querySelector('.search-form');
const searchInput = document.querySelector('.search-input');
const searchResults = document.querySelector('.search-results');
const markdownModal = document.querySelector('.markdown-modal');
let debounceTimeout;
const baseUrl = document.querySelector('meta[name="base-url"]')?.getAttribute('content') || '';
function getFullUrl(url) {
if (!url) return url;
if (baseUrl) {
const baseUrlPattern = new RegExp(`^(?:${baseUrl}/?)+`);
url = url.replace(baseUrlPattern, '');
}
url = url.replace(/^\/+/, '');
if (!baseUrl) return '/' + url;
return `${baseUrl}/${url}`;
}
fetch(getFullUrl('search-index.json'))
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
searchIndex = data;
console.log('Search index loaded successfully');
})
.catch(error => {
console.error('Error loading search index:', error);
searchResults.innerHTML = 'Search is currently unavailable';
});
function performSearch(query) {
if (!query || query.length < 2) {
searchResults.hidden = true;
return;
}
const queryLower = query.toLowerCase();
const results = searchIndex
.map(item => {
const title = String(item.title || '');
const description = String(item.description || '');
const content = String(item.content || '');
const tags = Array.isArray(item.tags) ? item.tags.map(tag => String(tag || '')) : [];
const titleScore = title.toLowerCase().includes(queryLower) ? 3 : 0;
const descriptionScore = description.toLowerCase().includes(queryLower) ? 2 : 0;
const contentScore = content.toLowerCase().includes(queryLower) ? 1 : 0;
const tagScore = tags.some(tag => tag.toLowerCase().includes(queryLower)) ? 2 : 0;
const totalScore = titleScore + descriptionScore + contentScore + tagScore;
return {
...item,
score: totalScore
};
})
.filter(item => item.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, 10);
displayResults(results);
}
function displayResults(results) {
searchResults.hidden = false;
if (results.length === 0) {
searchResults.innerHTML = 'No results found';
return;
}
const html = results.map(result => `
`).join('');
searchResults.innerHTML = html;
}
searchForm.addEventListener('submit', function(e) {
e.preventDefault();
performSearch(searchInput.value);
});
searchInput.addEventListener('input', function() {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
performSearch(searchInput.value);
}, 300);
});
document.addEventListener('click', function(e) {
if (!searchForm.contains(e.target) && !searchResults.contains(e.target)) {
searchResults.hidden = true;
}
});
searchResults.addEventListener('keydown', function(e) {
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault();
const links = searchResults.querySelectorAll('.result-link');
const currentIndex = Array.from(links).indexOf(document.activeElement);
let nextIndex;
if (e.key === 'ArrowDown') {
nextIndex = currentIndex < links.length - 1 ? currentIndex + 1 : 0;
} else {
nextIndex = currentIndex > 0 ? currentIndex - 1 : links.length - 1;
}
links[nextIndex].focus();
}
});
});