new starlight feature.... prep for expansion of astro-ghostcms
This commit is contained in:
parent
70b6fd2d16
commit
f078ebc063
|
@ -3,3 +3,6 @@
|
|||
---
|
||||
|
||||
Bumb GhostCMS API, No user facing breaking changes.
|
||||
|
||||
NEW:
|
||||
- You can now set a `route: "blog"` in your `astro.config.mjs` to change the default `/<route>` to your blog/posts
|
|
@ -78,11 +78,16 @@ export default function starlightGhostCMS(
|
|||
});
|
||||
};
|
||||
|
||||
makeRoute("blog", "index.astro");
|
||||
makeRoute("blog/[slug]", "[slug].astro");
|
||||
makeRoute("blog/about", "about.astro");
|
||||
makeRoute("blog/authors", "authors.astro");
|
||||
makeRoute("rss.xml", "rss.xml.ts");
|
||||
makeRoute(`${config.route}`,
|
||||
"index.astro");
|
||||
makeRoute(`${config.route}/[slug]`,
|
||||
"[slug].astro");
|
||||
makeRoute(`${config.route}/about`,
|
||||
"about.astro");
|
||||
makeRoute(`${config.route}/authors`,
|
||||
"authors.astro");
|
||||
makeRoute("rss.xml",
|
||||
"rss.xml.ts");
|
||||
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
---
|
||||
import StarlightMarkdownContent from '@astrojs/starlight/components/MarkdownContent.astro'
|
||||
import type { Props } from '@astrojs/starlight/props'
|
||||
|
||||
import config from 'virtual:starlight-ghostcms/config'
|
||||
import { isAnyBlogPostPage } from '../utils/page'
|
||||
import Metadata from '../components/Metadata.astro'
|
||||
import type { Post } from '../schemas/posts'
|
||||
|
||||
export function checkpath(path: string){
|
||||
return path.split('/').includes(config.route) ? true : false
|
||||
}
|
||||
|
||||
const isBlog = checkpath(Astro.url.pathname)
|
||||
const isBlogPost = isAnyBlogPostPage(Astro.props.slug)
|
||||
let blogEntry: Post | undefined = undefined
|
||||
|
||||
---
|
||||
|
||||
<StarlightMarkdownContent {...Astro.props}>
|
||||
{isBlogPost && blogEntry ? <Metadata entry={blogEntry} /> : null}
|
||||
{isBlog && blogEntry ? <Metadata entry={blogEntry} /> : null}
|
||||
<slot />
|
||||
|
||||
{
|
||||
isBlogPost && blogEntry ? (
|
||||
isBlog && blogEntry ? (
|
||||
<div class="post-footer">
|
||||
</div>
|
||||
) : null
|
||||
|
|
|
@ -17,19 +17,17 @@ export async function getBlogPageEntries(){
|
|||
}
|
||||
|
||||
export function checkpath(path: string){
|
||||
if ( path.slice(0, 5) === "/blog" ){
|
||||
return true
|
||||
} else { return false }
|
||||
return path.split('/').includes(config.route) ? true : false
|
||||
}
|
||||
|
||||
export function isAbout(path: string){
|
||||
if ( path === "/blog/about" ){
|
||||
if ( path === `/${config.route}/about` ){
|
||||
return true
|
||||
} else { return false }
|
||||
}
|
||||
|
||||
export function isAuthors(path: string){
|
||||
if ( path === "/blog/authors" ){
|
||||
if ( path === `/${config.route}/authors` ){
|
||||
return true
|
||||
} else { return false }
|
||||
}
|
||||
|
@ -38,7 +36,7 @@ const recentEntries = isBlog ? await getRecentBlogEntries() : []
|
|||
const aboutPage = await getSluggedPage("about");
|
||||
const AboutEntry:SidebarEntry = {
|
||||
attrs: {}, badge: undefined,
|
||||
href: '/blog/about',
|
||||
href: `/${config.route}/about`,
|
||||
isCurrent: isAbout(Astro.url.pathname),
|
||||
type: 'link',
|
||||
label: aboutPage?.post?.title
|
||||
|
@ -55,7 +53,7 @@ const blogSidebar: Props['sidebar'] = isBlog
|
|||
{
|
||||
attrs: {},
|
||||
badge: undefined,
|
||||
href: '/blog/authors',
|
||||
href: `/${config.route}/authors`,
|
||||
isCurrent: isAuthors(Astro.url.pathname),
|
||||
label: 'Our Authors',
|
||||
type: 'link',
|
||||
|
@ -63,7 +61,7 @@ const blogSidebar: Props['sidebar'] = isBlog
|
|||
{
|
||||
attrs: {},
|
||||
badge: undefined,
|
||||
href: '/blog',
|
||||
href: `/${config.route}`,
|
||||
isCurrent: isBlogRoot(Astro.props.slug),
|
||||
label: 'All posts',
|
||||
type: 'link',
|
||||
|
@ -74,8 +72,8 @@ const blogSidebar: Props['sidebar'] = isBlog
|
|||
entries: recentEntries.map((blogEntry) => ({
|
||||
attrs: {},
|
||||
badge: blogEntry.featured?({text: "⭐", variant: "note"}):undefined,
|
||||
href: `/blog/${blogEntry.slug}`,
|
||||
isCurrent: isBlogPostPage(Astro.props.slug, `blog/${blogEntry.slug}`),
|
||||
href: `/${config.route}/${blogEntry.slug}`,
|
||||
isCurrent: isBlogPostPage(Astro.props.slug, `${config.route}/${blogEntry.slug}`),
|
||||
label: blogEntry.title,
|
||||
type: 'link',
|
||||
})),
|
||||
|
@ -89,7 +87,7 @@ const blogSidebar: Props['sidebar'] = isBlog
|
|||
{
|
||||
!isBlog && (
|
||||
<div class="md:sl-hidden">
|
||||
<a href="/blog">Blog</a>
|
||||
<a href={`/${config.route}`}>Blog</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
---
|
||||
import type { Props } from "@astrojs/starlight/props";
|
||||
import AstrolightSiteTitle from "@astrojs/starlight/components/SiteTitle.astro";
|
||||
import config from 'virtual:starlight-ghostcms/config'
|
||||
---
|
||||
|
||||
<AstrolightSiteTitle {...Astro.props} />
|
||||
<div>
|
||||
<a href="/blog">Blog</a>
|
||||
<a href={`/${config.route}`}>{config.linkName}</a>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -22,7 +22,7 @@ export async function GET({ site }: APIContext) {
|
|||
post.published_at ? post.published_at : post.created_at,
|
||||
),
|
||||
description: post.excerpt,
|
||||
link: `/blog/${post.slug}/`,
|
||||
link: `/${config.route}/${post.slug}/`,
|
||||
author: post.primary_author?.name,
|
||||
})),
|
||||
});
|
||||
|
|
|
@ -11,6 +11,14 @@ const configSchema = z
|
|||
* The number of recent blog posts to display in the sidebar.
|
||||
*/
|
||||
recentPostCount: z.number().min(1).default(10),
|
||||
/**
|
||||
* Allows you to change the default route for the blog.
|
||||
*/
|
||||
route: z.string().default("blog"),
|
||||
/**
|
||||
* The name of the blog link in the navigation.
|
||||
*/
|
||||
linkName: z.string().default("Blog"),
|
||||
/**
|
||||
* The title of the blog.
|
||||
*/
|
||||
|
@ -24,7 +32,7 @@ const configSchema = z
|
|||
*/
|
||||
supportGhost: z.boolean().default(true),
|
||||
})
|
||||
.default({});
|
||||
.default({ postCount: 5, recentPostCount: 10, route: "blog", title: "Blog", rssDescription: "My Awesome Starlight-GhostCMS Blog", supportGhost: true});
|
||||
|
||||
export function validateConfig(userConfig: unknown): StarlightGhostConfig {
|
||||
const config = configSchema.safeParse(userConfig);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
export function isAnyBlogPage(slug: string) {
|
||||
return slug.match(/^blog(\/?$|\/.+\/?$)/) !== null;
|
||||
}
|
||||
import config from 'virtual:starlight-ghostcms/config'
|
||||
|
||||
export function isBlogRoot(slug: string) {
|
||||
return slug === "blog";
|
||||
}
|
||||
|
||||
export function isAnyBlogPostPage(slug: string) {
|
||||
return slug.match(/^blog\/(?!(\d+\/?|tags\/.+)$).+$/) !== null;
|
||||
const group = slug.split("/").pop();
|
||||
const currentslug = group?.[0];
|
||||
return currentslug;
|
||||
}
|
||||
|
||||
export function isBlogPostPage(slug: string, postSlug: string) {
|
||||
|
|
|
@ -10,9 +10,9 @@ export default defineConfig({
|
|||
title: "My Docs",
|
||||
plugins: [
|
||||
starlightGhostCMS({
|
||||
ghostURL: 'https://ghostdemo.matthiesen.xyz',
|
||||
title: "Demo Blog",
|
||||
rssDescription: "Starlight Playground",
|
||||
route: "blog",
|
||||
}),
|
||||
],
|
||||
social: {
|
||||
|
|
Loading…
Reference in New Issue