Skip to content
Merged
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
90 changes: 34 additions & 56 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import { defineConfig } from 'vitepress'
import { fileURLToPath, URL } from 'node:url'
import { fileURLToPath, URL, pathToFileURL } from 'node:url'
import blogSidebar from './theme/blog-sidebar.ts'
import {communitySidebar} from "./theme/community-sidebar.ts";
import path from 'path'
import { SearchResult } from 'minisearch'
import { generateEnhancedDocsSidebar } from './theme/docs-sidebar.ts';
import { hasMarkdownContent, getTaxonomyChildren } from './theme/utils/sidebar.ts';

const indexPattern = new RegExp(/\/?_?index\.md$/i);

// Pre-compute sidebar data at module level (runs once at build start)
const allSidebars = {
'/blog/': blogSidebar()['/blog/'],
'/community/': communitySidebar()['/community/'],
'/docs/': generateEnhancedDocsSidebar()['/docs/']
};

export default defineConfig({
base: process.env.VITE_PUBLIC_BASE_PATH || '',
srcDir: 'hugo/content',
cleanUrls: true,
transformPageData(pageData) {
// Only process index pages
if (!pageData.relativePath.endsWith('index.md')) return
Comment thread
klocke-io marked this conversation as resolved.

// Build the absolute file path
const configDir = path.dirname(fileURLToPath(import.meta.url))
const filePath = path.resolve(configDir, '..', 'hugo', 'content', pageData.relativePath)

// Check if the markdown body is empty
if (hasMarkdownContent(filePath)) return

// Look up sidebar children for this path
const children = getTaxonomyChildren(pageData.relativePath, allSidebars)
if (children && children.length > 0) {
pageData.frontmatter.taxonomyChildren = children
}
},
sitemap: {
hostname: 'https://gardener.cloud'
},
Expand Down Expand Up @@ -76,18 +102,9 @@ function getNavConfig () {
activeMatch: 'adopter',
},
{
component: 'VPNavbarMenuGroupWrapper',
props: {
text: 'Documentation',
link: '/docs/',
activeMatch: 'docs',
items: [
{text: 'User', link: '/docs/index.md',},
{text: 'Operator', link: '/docs/index.md',},
{text: 'Developer', link: '/docs/index.md',},
{text: 'All', link: '/docs/index.md',},
],
},
text: 'Documentation',
activeMatch: 'docs',
link: '/docs',
},
{
text: 'Blog',
Expand Down Expand Up @@ -178,30 +195,9 @@ function getThemeConfig() {
isNetlify: process.env.NETLIFY === 'true',
logo: {src: '/gardener-logo.svg', width: 24, height: 24},
nav: getNavConfig(),
sidebar: {
'/blog/': blogSidebar()['/blog/'],
//@ts-ignore
'/community/': communitySidebar()['/community/'],
//@ts-ignore
'/docs/': { //generateEnhancedDocsSidebar()['/docs/'],
"base": "/docs/",
"text": "Docs",
"items": [
{
"text": "Gardener",
"link": "gardener/index.md",
"items": [
{
"text": "Concepts",
"link": "gardener/concepts/index.md",
}
]
}
],
},
},
sidebar: allSidebars,
editLink: {
pattern: ({filePath, frontmatter}) => {
pattern: ({filePath, frontmatter}: {filePath: string, frontmatter: Record<string, any>}) => {
const fileName = `${frontmatter?.path_base_for_github_subdir?.to ?? filePath.split("/").pop()}`
const githubLink = `${frontmatter['github_repo']}/tree/master/${frontmatter['github_subdir']}/${fileName}`
return githubLink
Expand Down Expand Up @@ -247,11 +243,11 @@ function getViteConfig() {
alias: [
{
find: '@data',
replacement: path.resolve(__dirname, './data')
replacement: path.resolve(path.dirname(fileURLToPath(import.meta.url)), './data')
},
{
find: '@components',
replacement: path.resolve(__dirname, './theme/components')
replacement: path.resolve(path.dirname(fileURLToPath(import.meta.url)), './theme/components')
},
{
find: /^.*\/VPFeature\.vue$/,
Expand All @@ -265,24 +261,6 @@ function getViteConfig() {
new URL('./theme/components/VPTeamMembersItem.vue', import.meta.url)
)
},
{
find: /^.*\/VPNavBarMenuLink\.vue$/,
replacement: fileURLToPath(
new URL('./theme/components/VPNavBarMenuLink.vue', import.meta.url)
)
},
{
find: /^.*\/VPSidebarGroup\.vue$/,
replacement: fileURLToPath(
new URL('./theme/components/VPSidebarGroup.vue', import.meta.url)
)
},
{
find: /^.*\/VPMenu\.vue$/,
replacement: fileURLToPath(
new URL('./theme/components/VPMenu.vue', import.meta.url)
)
},
]
}
}
Expand Down
14 changes: 0 additions & 14 deletions .vitepress/data/sidebar.data.ts

This file was deleted.

60 changes: 12 additions & 48 deletions .vitepress/theme/community-sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
import { generateSidebar } from 'vitepress-sidebar';
import { writeJsonDebug } from './utils/debug-json.ts';
import {
removeIndexEntries,
sortByWeight,
enhanceDirectoryTitles,
removeEmptyItems,
addTrailingSlashToLinks,
} from './utils/sidebar.ts';

const communitySidbarConfig = {
documentRootPath: '/hugo/content',
scanStartPath: 'community',
resolvePath: '/community/',
collapsed: true,
useTitleFromFileHeading: true,
useTitleFromFrontmatter: true,
useFolderLinkFromIndexFile: true,
includeFolderLinksInFolder: true,
excludeFilesByFrontmatterFieldName: 'exclude',
}
import { generateWeightSortedSidebar } from './utils/sidebar.ts';

export function communitySidebar(): any {
// Generate the base sidebar
const sidebar = generateSidebar([communitySidbarConfig]);

// Recursively enhance directory titles from frontmatter
const enhancedSidebar = enhanceDirectoryTitles(sidebar, 'community');

// Sort entries by weight from frontmatter
const sortedSidebar = sortByWeight(enhancedSidebar, 'community');

// Filter out all _index.md entries (called last)
const filteredSidebar = removeIndexEntries(sortedSidebar)

writeJsonDebug(
'filteredCommunitySidebar.json',
filteredSidebar
);

const cleandSidebar = removeEmptyItems(filteredSidebar)

writeJsonDebug(
'cleandCommunitySidebar.json',
cleandSidebar
);

addTrailingSlashToLinks(cleandSidebar['/community/'].items);

return cleandSidebar;
return generateWeightSortedSidebar({
documentRootPath: '/hugo/content',
scanStartPath: 'community',
resolvePath: '/community/',
collapsed: true,
useTitleFromFileHeading: true,
useTitleFromFrontmatter: true,
useFolderLinkFromIndexFile: true,
useFolderTitleFromIndexFile: true,
excludeFilesByFrontmatterFieldName: 'exclude',
});
}
59 changes: 0 additions & 59 deletions .vitepress/theme/components/CustomVPMenuLink.vue

This file was deleted.

57 changes: 57 additions & 0 deletions .vitepress/theme/components/TaxonomyIndex.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script setup lang="ts">
import { useData } from 'vitepress'
import { computed } from 'vue'

const { frontmatter, page } = useData()

const children = computed(() => frontmatter.value.taxonomyChildren as Array<{ text: string; link: string }> | undefined)

const pageTitle = computed(() => {
return frontmatter.value.title || page.value.title || ''
})
</script>

<template>
<div v-if="children?.length" class="taxonomy-index">
<h1>{{ pageTitle }}</h1>
<ul class="taxonomy-list">
<li v-for="child in children" :key="child.link">
<a :href="child.link">{{ child.text }}</a>
</li>
</ul>
</div>
</template>

<style scoped>
.taxonomy-index {
margin-bottom: 1rem;
}

.taxonomy-index h1 {
font-size: 2rem;
font-weight: 600;
line-height: 1.25;
margin-bottom: 1rem;
}

.taxonomy-list {
list-style: disc;
padding-left: 1.5rem;
}

.taxonomy-list li {
margin: 0.4rem 0;
}

.taxonomy-list a {
color: var(--vp-c-brand-1);
text-decoration: none;
font-size: 1rem;
transition: color 0.2s;
}

.taxonomy-list a:hover {
color: var(--vp-c-brand-2);
text-decoration: underline;
}
</style>
Loading