Skip to content

Commit

Permalink
Experiment with custom sidebar.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlex94 committed Oct 25, 2023
1 parent ec53e1e commit 5742461
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +46,10 @@ export default defineConfig({
twitter: 'https://twitter.com/Waterfoxproject'
},
sidebar: [
{
label: 'Blog',
autogenerate: { directory: 'blog' }
},
{
label: 'Policies',
autogenerate: { directory: 'docs/policies' }
Expand Down
42 changes: 42 additions & 0 deletions src/components/Sidebar.astro
Original file line number Diff line number Diff line change
@@ -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))
---

<StarlightSidebar {...{ ...Astro.props, sidebar: filteredSublist }} />

0 comments on commit 5742461

Please sign in to comment.