more progress

This commit is contained in:
Adam Matthiesen 2024-02-19 21:58:36 -08:00
parent b462c105b5
commit d16a23dcd7
16 changed files with 105 additions and 39 deletions

View File

@ -15,7 +15,10 @@
"test:api": "pnpm --filter astro-ghostcms test", "test:api": "pnpm --filter astro-ghostcms test",
"test:api:watch": "pnpm --filter astro-ghostcms test:watch", "test:api:watch": "pnpm --filter astro-ghostcms test:watch",
"test:api:coverage": "pnpm --filter astro-ghostcms test:coverage", "test:api:coverage": "pnpm --filter astro-ghostcms test:coverage",
"test:create": "pnpm --filter create-astro-ghostcms test" "test:create": "pnpm --filter create-astro-ghostcms test",
"test:slg": "pnpm --filter starlight-ghostcms test",
"test:slg:watch": "pnpm --filter starlight-ghostcms test:watch",
"test:slg:coverage": "pnpm --filter starlight-ghostcms test:coverage"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.5.3", "@biomejs/biome": "1.5.3",

View File

@ -30,6 +30,13 @@ export default function starlightBlogPlugin(userConfig?: StarlightGhostConfig):
entrypoint: '/blog', entrypoint: '/blog',
prerender: true, prerender: true,
}) })
/** THIS IS NOT READY
* injectRoute({
* pattern: '@matthiesenxyz/starlight-ghostcms/routes/[slug].astro',
* entrypoint: '/blog/[slug]',
* prerender: true,
* })
*/
updateConfig({ updateConfig({
vite: { vite: {

View File

@ -45,17 +45,24 @@
"./overrides/Sidebar.astro": "./src/overrides/SideBar.astro", "./overrides/Sidebar.astro": "./src/overrides/SideBar.astro",
"./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro", "./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro",
"./routes/index.astro": "./src/routes/index.astro", "./routes/index.astro": "./src/routes/index.astro",
"./routes/[slug].astro": "./src/routes/[slug].astro",
"./schema": "./src/schemas/config.ts", "./schema": "./src/schemas/config.ts",
"./package.json": "./package.json" "./package.json": "./package.json"
}, },
"scripts": { "scripts": {
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:ci": "vitest run --coverage.enabled --coverage.reporter='text-summary'"
}, },
"devDependencies": { "devDependencies": {
"@astrojs/starlight": "0.19.0", "@astrojs/starlight": "0.19.0",
"@ts-ghost/core-api": "5.1.2", "@ts-ghost/core-api": "5.1.2",
"@ts-ghost/tsconfig": "workspace:*",
"astro": "4.3.7",
"vite": "^5.1.2", "vite": "^5.1.2",
"astro": "4.3.7" "vite-tsconfig-paths": "^4.2.2",
"vitest": "^1.2.2",
"vitest-fetch-mock": "^0.2.2"
}, },
"peerdependencies": { "peerdependencies": {
"@astrojs/starlight": ">=0.19.0", "@astrojs/starlight": ">=0.19.0",

View File

@ -14,7 +14,7 @@ const Excerpt = entry.excerpt
<article class="preview"> <article class="preview">
<header> <header>
<h2> <h2>
<a href={`/${entry.slug}`}>{entry.title}</a> <a href={`/blog/${entry.slug}`}>{entry.title}</a>
</h2> </h2>
<Metadata entry={entry} /> <Metadata entry={entry} />
</header> </header>

View File

@ -11,14 +11,15 @@ const isBlogPost = isAnyBlogPostPage(Astro.props.slug)
let blogEntry: Post | undefined = undefined let blogEntry: Post | undefined = undefined
if (isBlogPost) { if (isBlogPost) {
blogEntry = await getSluggedPost(Astro.props.slug) const post = await getSluggedPost(Astro.props.slug)
blogEntry = post.post
} }
--- ---
<StarlightMarkdownContent {...Astro.props}> <StarlightMarkdownContent {...Astro.props}>
{isBlogPost && blogEntry ? <Metadata entry={blogEntry} /> : null} {isBlogPost && blogEntry ? <Metadata entry={blogEntry} /> : null}
<slot />
<div> PlaceHolder for HTML </div> <div> {isBlogPost && blogEntry?.plaintext} </div>
{ {
isBlogPost && blogEntry ? ( isBlogPost && blogEntry ? (

View File

@ -1,9 +1,14 @@
--- ---
import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro' import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro'
import type { Props } from '@astrojs/starlight/props' import type { Props } from '@astrojs/starlight/props'
import config from 'virtual:starlight-ghost-config'
import { getRecentBlogEntries } from '../utils/content'
import { isAnyBlogPage, isBlogPostPage, isBlogRoot } from '../utils/page' import { isAnyBlogPage, isBlogPostPage, isBlogRoot } from '../utils/page'
import { getAllPosts } from '../utils/api'
export async function getRecentBlogEntries(){
const entries = await getAllPosts()
return entries.slice(0, config.recentPostCount)
}
const isBlog = isAnyBlogPage(Astro.props.slug) const isBlog = isAnyBlogPage(Astro.props.slug)
const recentEntries = isBlog ? await getRecentBlogEntries() : [] const recentEntries = isBlog ? await getRecentBlogEntries() : []
@ -24,9 +29,9 @@ const blogSidebar: Props['sidebar'] = isBlog
entries: recentEntries.map((blogEntry) => ({ entries: recentEntries.map((blogEntry) => ({
attrs: {}, attrs: {},
badge: undefined, badge: undefined,
href: `/${blogEntry.slug}`, href: `/blog/${blogEntry.slug}`,
isCurrent: isBlogPostPage(Astro.props.slug, blogEntry.slug), isCurrent: isBlogPostPage(Astro.props.slug, blogEntry.slug),
label: blogEntry.data.title, label: blogEntry.title,
type: 'link', type: 'link',
})), })),
label: 'Recent posts', label: 'Recent posts',

View File

@ -68,20 +68,19 @@ export const getAllPosts = async () => {
}; };
export const getSluggedPost = async (slug:string) => { export const getSluggedPost = async (slug:string) => {
const result = await api.posts const results = await api.posts
.read({slug: slug}) .read({slug: slug})
.include({ .include({
authors: true, authors: true,
tags: true, tags: true,
}).fetch() }).fetch()
if (result.success) { if (!results.success) {
const post: Post = result.data; throw new Error(results.errors.map((e) => e.message).join(", "));
return post }
} return {
if (result.errors) { post: results.data,
console.log(result.errors.map((e) => e.message).join("\n")); };
}
}; };
export const getAllPages = async () => { export const getAllPages = async () => {

View File

@ -3,7 +3,7 @@ import {
ghostMetaSchema, ghostMetaSchema,
ghostMetadataSchema, ghostMetadataSchema,
} from "@ts-ghost/core-api"; } from "@ts-ghost/core-api";
import { z } from "zod"; import { z } from "astro/zod";
export const authorsSchema = z.object({ export const authorsSchema = z.object({
...ghostIdentitySchema.shape, ...ghostIdentitySchema.shape,

View File

@ -5,7 +5,7 @@ import {
ghostSocialMediaSchema, ghostSocialMediaSchema,
ghostVisibilitySchema, ghostVisibilitySchema,
} from "@ts-ghost/core-api"; } from "@ts-ghost/core-api";
import { z } from "zod"; import { z } from "astro/zod";
import { authorsSchema } from "../authors"; import { authorsSchema } from "../authors";
import { tagsSchema } from "../tags"; import { tagsSchema } from "../tags";

View File

@ -5,7 +5,7 @@ import {
ghostSocialMediaSchema, ghostSocialMediaSchema,
ghostVisibilitySchema, ghostVisibilitySchema,
} from "@ts-ghost/core-api"; } from "@ts-ghost/core-api";
import { z } from "zod"; import { z } from "astro/zod";
import { authorsSchema } from "../authors"; import { authorsSchema } from "../authors";
import { tagsSchema } from "../tags"; import { tagsSchema } from "../tags";

View File

@ -1,4 +1,4 @@
import { z } from "zod"; import { z } from "astro/zod";
export const settingsSchema = z.object({ export const settingsSchema = z.object({
title: z.string(), title: z.string(),

View File

@ -5,7 +5,7 @@ import {
ghostSocialMediaSchema, ghostSocialMediaSchema,
ghostVisibilitySchema, ghostVisibilitySchema,
} from "@ts-ghost/core-api"; } from "@ts-ghost/core-api";
import { z } from "zod"; import { z } from "astro/zod";
export const tagsSchema = z.object({ export const tagsSchema = z.object({
...ghostIdentitySchema.shape, ...ghostIdentitySchema.shape,

View File

@ -1,5 +1,5 @@
import { ghostIdentitySchema, ghostVisibilitySchema } from "@ts-ghost/core-api"; import { ghostIdentitySchema, ghostVisibilitySchema } from "@ts-ghost/core-api";
import { z } from "zod"; import { z } from "astro/zod";
export const tiersSchema = z.object({ export const tiersSchema = z.object({
...ghostIdentitySchema.shape, ...ghostIdentitySchema.shape,

View File

@ -0,0 +1,15 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />
import tsconfigPaths from "vite-tsconfig-paths";
import { defineProject } from "vitest/config";
export default defineProject({
plugins: [tsconfigPaths()],
test: {
globals: true,
include: ["./**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
watchExclude: [".*\\/node_modules\\/.*", ".*\\/build\\/.*"],
exclude: ["node_modules", "dist", ".idea", ".git", ".cache"],
},
});

View File

@ -134,7 +134,7 @@ importers:
version: link:../astro-ghostcms-rendercontent version: link:../astro-ghostcms-rendercontent
'@unocss/astro': '@unocss/astro':
specifier: ^0.58.5 specifier: ^0.58.5
version: 0.58.5(vite@5.1.2) version: 0.58.5(vite@5.1.3)
'@unocss/reset': '@unocss/reset':
specifier: ^0.58.5 specifier: ^0.58.5
version: 0.58.5 version: 0.58.5
@ -152,7 +152,7 @@ importers:
version: 1.5.2 version: 1.5.2
unocss: unocss:
specifier: ^0.58.5 specifier: ^0.58.5
version: 0.58.5(postcss@8.4.35)(vite@5.1.2) version: 0.58.5(postcss@8.4.35)(vite@5.1.3)
devDependencies: devDependencies:
'@typescript-eslint/parser': '@typescript-eslint/parser':
specifier: ^7.0.1 specifier: ^7.0.1
@ -310,12 +310,24 @@ importers:
'@ts-ghost/core-api': '@ts-ghost/core-api':
specifier: 5.1.2 specifier: 5.1.2
version: 5.1.2 version: 5.1.2
'@ts-ghost/tsconfig':
specifier: workspace:*
version: link:../tsconfig
astro: astro:
specifier: 4.3.7 specifier: 4.3.7
version: 4.3.7(sass@1.70.0)(typescript@5.3.3) version: 4.3.7(sass@1.70.0)(typescript@5.3.3)
vite: vite:
specifier: ^5.1.2 specifier: ^5.1.2
version: 5.1.2(sass@1.70.0) version: 5.1.2(sass@1.70.0)
vite-tsconfig-paths:
specifier: ^4.2.2
version: 4.3.1(vite@5.1.2)
vitest:
specifier: ^1.2.2
version: 1.2.2(@vitest/ui@1.2.2)
vitest-fetch-mock:
specifier: ^0.2.2
version: 0.2.2(vitest@1.2.2)
packages/tsconfig: {} packages/tsconfig: {}
@ -338,7 +350,7 @@ importers:
version: link:../packages/astro-ghostcms-theme-default version: link:../packages/astro-ghostcms-theme-default
'@unocss/astro': '@unocss/astro':
specifier: ^0.58.5 specifier: ^0.58.5
version: 0.58.5(vite@5.1.2) version: 0.58.5(vite@5.1.3)
astro: astro:
specifier: ^4.3.7 specifier: ^4.3.7
version: 4.3.7(sass@1.70.0)(typescript@5.3.3) version: 4.3.7(sass@1.70.0)(typescript@5.3.3)
@ -354,7 +366,7 @@ importers:
version: 5.3.3 version: 5.3.3
unocss: unocss:
specifier: ^0.58.5 specifier: ^0.58.5
version: 0.58.5(postcss@8.4.35)(vite@5.1.2) version: 0.58.5(postcss@8.4.35)(vite@5.1.3)
packages: packages:
@ -2446,7 +2458,7 @@ packages:
/@ungap/structured-clone@1.2.0: /@ungap/structured-clone@1.2.0:
resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
/@unocss/astro@0.58.5(vite@5.1.2): /@unocss/astro@0.58.5(vite@5.1.3):
resolution: {integrity: sha512-LtuVnj8oFAK9663OVhQO8KpdJFiOyyPsYfnOZlDCOFK3gHb/2WMrzdBwr1w8LoQF3bDedkFMKirVF7gWjyZiaw==} resolution: {integrity: sha512-LtuVnj8oFAK9663OVhQO8KpdJFiOyyPsYfnOZlDCOFK3gHb/2WMrzdBwr1w8LoQF3bDedkFMKirVF7gWjyZiaw==}
peerDependencies: peerDependencies:
vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0
@ -2456,8 +2468,8 @@ packages:
dependencies: dependencies:
'@unocss/core': 0.58.5 '@unocss/core': 0.58.5
'@unocss/reset': 0.58.5 '@unocss/reset': 0.58.5
'@unocss/vite': 0.58.5(vite@5.1.2) '@unocss/vite': 0.58.5(vite@5.1.3)
vite: 5.1.2(sass@1.70.0) vite: 5.1.3(@types/node@20.11.18)(sass@1.71.0)
transitivePeerDependencies: transitivePeerDependencies:
- rollup - rollup
@ -2617,7 +2629,7 @@ packages:
dependencies: dependencies:
'@unocss/core': 0.58.5 '@unocss/core': 0.58.5
/@unocss/vite@0.58.5(vite@5.1.2): /@unocss/vite@0.58.5(vite@5.1.3):
resolution: {integrity: sha512-p4o1XNX1rvjmoUqSSdua8XyWNg/d+YUChDd2L/xEty+6j2qv0wUaohs3UQ87vWlv632/UmgdX+2MbrgtqthCtw==} resolution: {integrity: sha512-p4o1XNX1rvjmoUqSSdua8XyWNg/d+YUChDd2L/xEty+6j2qv0wUaohs3UQ87vWlv632/UmgdX+2MbrgtqthCtw==}
peerDependencies: peerDependencies:
vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0
@ -2632,7 +2644,7 @@ packages:
chokidar: 3.6.0 chokidar: 3.6.0
fast-glob: 3.3.2 fast-glob: 3.3.2
magic-string: 0.30.7 magic-string: 0.30.7
vite: 5.1.2(sass@1.70.0) vite: 5.1.3(@types/node@20.11.18)(sass@1.71.0)
transitivePeerDependencies: transitivePeerDependencies:
- rollup - rollup
@ -8398,7 +8410,7 @@ packages:
resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==}
engines: {node: '>= 10.0.0'} engines: {node: '>= 10.0.0'}
/unocss@0.58.5(postcss@8.4.35)(vite@5.1.2): /unocss@0.58.5(postcss@8.4.35)(vite@5.1.3):
resolution: {integrity: sha512-0g4P6jLgRRNnhscxw7nQ9RHGrKJ1UPPiHPet+YT3TXUcmy4mTiYgo9+kGQf5bjyrzsELJ10cT6Qz2y6g9Tls4g==} resolution: {integrity: sha512-0g4P6jLgRRNnhscxw7nQ9RHGrKJ1UPPiHPet+YT3TXUcmy4mTiYgo9+kGQf5bjyrzsELJ10cT6Qz2y6g9Tls4g==}
engines: {node: '>=14'} engines: {node: '>=14'}
peerDependencies: peerDependencies:
@ -8410,7 +8422,7 @@ packages:
vite: vite:
optional: true optional: true
dependencies: dependencies:
'@unocss/astro': 0.58.5(vite@5.1.2) '@unocss/astro': 0.58.5(vite@5.1.3)
'@unocss/cli': 0.58.5 '@unocss/cli': 0.58.5
'@unocss/core': 0.58.5 '@unocss/core': 0.58.5
'@unocss/extractor-arbitrary-variants': 0.58.5 '@unocss/extractor-arbitrary-variants': 0.58.5
@ -8429,8 +8441,8 @@ packages:
'@unocss/transformer-compile-class': 0.58.5 '@unocss/transformer-compile-class': 0.58.5
'@unocss/transformer-directives': 0.58.5 '@unocss/transformer-directives': 0.58.5
'@unocss/transformer-variant-group': 0.58.5 '@unocss/transformer-variant-group': 0.58.5
'@unocss/vite': 0.58.5(vite@5.1.2) '@unocss/vite': 0.58.5(vite@5.1.3)
vite: 5.1.2(sass@1.70.0) vite: 5.1.3(@types/node@20.11.18)(sass@1.71.0)
transitivePeerDependencies: transitivePeerDependencies:
- postcss - postcss
- rollup - rollup
@ -8537,7 +8549,7 @@ packages:
debug: 4.3.4 debug: 4.3.4
pathe: 1.1.2 pathe: 1.1.2
picocolors: 1.0.0 picocolors: 1.0.0
vite: 5.1.2(@types/node@20.11.18) vite: 5.1.3(@types/node@20.11.18)(sass@1.71.0)
transitivePeerDependencies: transitivePeerDependencies:
- '@types/node' - '@types/node'
- less - less
@ -8581,6 +8593,23 @@ packages:
- supports-color - supports-color
- typescript - typescript
/vite-tsconfig-paths@4.3.1(vite@5.1.2):
resolution: {integrity: sha512-cfgJwcGOsIxXOLU/nELPny2/LUD/lcf1IbfyeKTv2bsupVbTH/xpFtdQlBmIP1GEK2CjjLxYhFfB+QODFAx5aw==}
peerDependencies:
vite: '*'
peerDependenciesMeta:
vite:
optional: true
dependencies:
debug: 4.3.4
globrex: 0.1.2
tsconfck: 3.0.2(typescript@5.3.3)
vite: 5.1.2(sass@1.70.0)
transitivePeerDependencies:
- supports-color
- typescript
dev: true
/vite@5.1.2(@types/node@20.11.18): /vite@5.1.2(@types/node@20.11.18):
resolution: {integrity: sha512-uwiFebQbTWRIGbCaTEBVAfKqgqKNKMJ2uPXsXeLIZxM8MVMjoS3j0cG8NrPxdDIadaWnPSjrkLWffLSC+uiP3Q==} resolution: {integrity: sha512-uwiFebQbTWRIGbCaTEBVAfKqgqKNKMJ2uPXsXeLIZxM8MVMjoS3j0cG8NrPxdDIadaWnPSjrkLWffLSC+uiP3Q==}
engines: {node: ^18.0.0 || >=20.0.0} engines: {node: ^18.0.0 || >=20.0.0}