From 5742461653280e0b15acd976f4cc27297ded2d5f Mon Sep 17 00:00:00 2001 From: Alex Kontos Date: Tue, 24 Oct 2023 20:30:46 +0100 Subject: [PATCH] Experiment with custom sidebar. --- astro.config.mjs | 7 +++++- src/components/Sidebar.astro | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/components/Sidebar.astro diff --git a/astro.config.mjs b/astro.config.mjs index bd09875..7ce7395 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -22,7 +22,8 @@ export default defineConfig({ components: { MarkdownContent: 'starlight-blog/overrides/MarkdownContent.astro', PageFrame: '~/components/CustomPageFrame.astro', - Sidebar: 'starlight-blog/overrides/Sidebar.astro', + Sidebar: '~/components/Sidebar.astro', + // Sidebar: 'starlight-blog/overrides/Sidebar.astro', ThemeSelect: '~/components/NavBar.astro' }, defaultLocale: 'root', // optional @@ -45,6 +46,10 @@ export default defineConfig({ twitter: 'https://twitter.com/Waterfoxproject' }, sidebar: [ + { + label: 'Blog', + autogenerate: { directory: 'blog' } + }, { label: 'Policies', autogenerate: { directory: 'docs/policies' } diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro new file mode 100644 index 0000000..dc190bf --- /dev/null +++ b/src/components/Sidebar.astro @@ -0,0 +1,42 @@ +--- +import type { Props } from '@astrojs/starlight/props' + +import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro' + +const { sidebar } = Astro.props +const { slug } = Astro.params + +var filteredSublist +if (slug?.includes('blog')) { + filteredSublist = sidebar.filter((group) => { + const entries = group.entries.filter((entry) => { + return entry.type === 'link' && entry.href?.includes('blog') + }) + + if (entries.length > 0) { + return { + ...group, + entries + } + } + }) + console.log(JSON.stringify('Blog ' + filteredSublist)) +} else { + filteredSublist = sidebar.filter((group) => { + const entries = group.entries.filter((entry) => { + return entry.type === 'link' && !entry.href?.includes('blog') + }) + + if (entries.length > 0) { + return { + ...group, + entries + } + } + }) + console.log(JSON.stringify('Not Blog ' + filteredSublist)) +} +console.log('Used value ' + JSON.stringify(filteredSublist)) +--- + +