diff --git a/packages/starlight-ghostcms/index.ts b/packages/starlight-ghostcms/index.ts index ad9f00ae..0c018270 100644 --- a/packages/starlight-ghostcms/index.ts +++ b/packages/starlight-ghostcms/index.ts @@ -2,12 +2,16 @@ import type { StarlightPlugin, StarlightUserConfig } from '@astrojs/starlight/ty import type { AstroIntegrationLogger } from 'astro' import { type StarlightGhostConfig, validateConfig } from './src/schemas/config' import { vitePluginStarlightGhostConfig } from './src/integrations/vite' +import { facebook, getSettings, invariant, twitter } from './src/utils/api' + +const settings = await getSettings() export type { StarlightGhostConfig } export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): StarlightPlugin { const config: StarlightGhostConfig = validateConfig(userConfig) - + invariant(settings, "Settings not available... check your api key/url") + return { name: '@matthiesenxyz/starlight-ghostcms-plugin', hooks: { @@ -15,7 +19,9 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St updateStarlightConfig({ social: { ...starlightConfig.social, - rss: `${astroConfig.site}/rss.xml` + rss: `${astroConfig.site}/rss.xml`, + twitter: twitter(settings.twitter?settings.twitter:""), + facebook: facebook(settings.facebook?settings.facebook:""), }, components: { ...starlightConfig.components, @@ -39,6 +45,15 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/[slug].astro', prerender: true, }) + injectRoute({ + pattern: '/blog/about', + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/about.astro', + prerender: true, + }) + injectRoute({ + pattern: '/blog/authors', + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/authors.astro', + }) injectRoute({ pattern: '/rss.xml', entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/rss.xml.ts' diff --git a/packages/starlight-ghostcms/package.json b/packages/starlight-ghostcms/package.json index deb081fd..b2a7d8ff 100644 --- a/packages/starlight-ghostcms/package.json +++ b/packages/starlight-ghostcms/package.json @@ -46,6 +46,8 @@ "./overrides/Sidebar.astro": "./src/overrides/Sidebar.astro", "./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro", "./routes/index.astro": "./src/routes/index.astro", + "./routes/about.astro": "./src/routes/about.astro", + "./routes/authors.astro": "./src/routes/authors.astro", "./routes/[slug].astro": "./src/routes/[slug].astro", "./routes/rss.xml.ts": "./src/routes/rss.xml.ts", "./schema": "./src/schemas/config.ts" diff --git a/packages/starlight-ghostcms/src/components/AdvancedAuthorCard.astro b/packages/starlight-ghostcms/src/components/AdvancedAuthorCard.astro new file mode 100644 index 00000000..fd16ec71 --- /dev/null +++ b/packages/starlight-ghostcms/src/components/AdvancedAuthorCard.astro @@ -0,0 +1,70 @@ +--- +import type { Author } from '../schemas/authors' +import { facebook } from '../utils/api' + +interface Props { + author: Author +} + +const { author } = Astro.props + +--- + +
+ {author.profile_image && {author.name}} +
+
{author.name}
+ {author.website && + + } + {author.facebook && + + } + {author.twitter && + + } + {author.bio &&
{author.bio}
} + + +
+
+ + diff --git a/packages/starlight-ghostcms/src/components/Author.astro b/packages/starlight-ghostcms/src/components/Author.astro index bbf982a7..bfacf6e3 100644 --- a/packages/starlight-ghostcms/src/components/Author.astro +++ b/packages/starlight-ghostcms/src/components/Author.astro @@ -7,11 +7,11 @@ interface Props { const { author } = Astro.props -const isLink = author.website !== undefined +const isLink = author.slug !== undefined const Element = isLink ? 'a' : 'div' --- - + {author.profile_image && {author.name}}
{author.name}
diff --git a/packages/starlight-ghostcms/src/overrides/Sidebar.astro b/packages/starlight-ghostcms/src/overrides/Sidebar.astro index 9e091e04..a75b80b9 100644 --- a/packages/starlight-ghostcms/src/overrides/Sidebar.astro +++ b/packages/starlight-ghostcms/src/overrides/Sidebar.astro @@ -3,23 +3,63 @@ import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro' import type { Props } from '@astrojs/starlight/props' import config from 'virtual:starlight-ghost-config' import { isBlogPostPage, isBlogRoot } from '../utils/page' -import { getAllPosts } from '../utils/api' +import { getAllPages, getAllPosts, getSluggedPage } from '../utils/api/api-functions.js' +import type { SidebarEntry } from './sidebartypes' export async function getRecentBlogEntries(){ const entries = await getAllPosts() return entries.slice(0, config.recentPostCount) } +export async function getBlogPageEntries(){ + const entries = await getAllPages() + return entries; +} + export function checkpath(path: string){ if ( path.slice(0, 5) === "/blog" ){ return true } else { return false } } + +export function isAbout(path: string){ + if ( path === "/blog/about" ){ + return true + } else { return false } +} + +export function isAuthors(path: string){ + if ( path === "/blog/authors" ){ + return true + } else { return false } +} const isBlog = checkpath(Astro.url.pathname) const recentEntries = isBlog ? await getRecentBlogEntries() : [] +const aboutPage = await getSluggedPage("about"); +const AboutEntry:SidebarEntry = { + attrs: {}, badge: undefined, + href: '/blog/about', + isCurrent: isAbout(Astro.url.pathname), + type: 'link', + label: aboutPage?.post?.title +} + +const emptyEntry:SidebarEntry = { attrs: {}, badge: undefined, + href: '#', isCurrent: false, type: 'link', label: '', } + +const about = aboutPage?AboutEntry:emptyEntry const blogSidebar: Props['sidebar'] = isBlog ? [ + about, + { + attrs: {}, + badge: undefined, + href: '/blog/authors', + isCurrent: isAuthors(Astro.url.pathname), + label: 'Our Authors', + type: 'link', + }, { attrs: {}, badge: undefined, @@ -33,7 +73,7 @@ const blogSidebar: Props['sidebar'] = isBlog collapsed: false, entries: recentEntries.map((blogEntry) => ({ attrs: {}, - badge: undefined, + badge: blogEntry.featured?({text: "⭐", variant: "note"}):undefined, href: `/blog/${blogEntry.slug}`, isCurrent: isBlogPostPage(Astro.props.slug, `blog/${blogEntry.slug}`), label: blogEntry.title, diff --git a/packages/starlight-ghostcms/src/overrides/SiteTitle.astro b/packages/starlight-ghostcms/src/overrides/SiteTitle.astro index 3f5dd01a..328b4874 100644 --- a/packages/starlight-ghostcms/src/overrides/SiteTitle.astro +++ b/packages/starlight-ghostcms/src/overrides/SiteTitle.astro @@ -1,12 +1,11 @@ --- import type { Props } from "@astrojs/starlight/props"; import AstrolightSiteTitle from "@astrojs/starlight/components/SiteTitle.astro"; -import config from 'virtual:starlight-ghost-config' ---
- {config.title} + Blog
\ No newline at end of file diff --git a/packages/starlight-ghostcms/src/routes/authors.astro b/packages/starlight-ghostcms/src/routes/authors.astro new file mode 100644 index 00000000..0d965af0 --- /dev/null +++ b/packages/starlight-ghostcms/src/routes/authors.astro @@ -0,0 +1,48 @@ +--- +import config from 'virtual:starlight-ghost-config' +import Page from '../components/Page.astro' +//import PrevNextLinks from '../components/PrevNextLinks.astro' +import { getAllAuthors } from '../utils/api/api-functions' +import { getPageProps } from '../utils/page' +import AdvancedAuthorCard from '../components/AdvancedAuthorCard.astro'; + +//const { entries, nextLink, prevLink } = Astro.props + +const { authors } = await getAllAuthors(); + +const pageProps = getPageProps("Our Authors") +--- + + + {config.supportGhost && ( +
Powered by Ghost
+ )} + + +
+
    + {authors.map((author: any) => ( +
  • + +
  • + ))} +
+ +
+ +
+ + + \ No newline at end of file diff --git a/packages/starlight-ghostcms/src/utils/api/api-functions.ts b/packages/starlight-ghostcms/src/utils/api/api-functions.ts index 57fa7b7f..e513b3ce 100644 --- a/packages/starlight-ghostcms/src/utils/api/api-functions.ts +++ b/packages/starlight-ghostcms/src/utils/api/api-functions.ts @@ -106,6 +106,22 @@ export const getAllPages = async () => { return pages; }; +export const getSluggedPage = async (slug:string) => { + const results = await api.pages + .read({slug: slug}) + .include({ + authors: true, + tags: true, + }).fetch() + + if (!results.success) { + throw new Error(results.errors.map((e) => e.message).join(", ")); + } + return { + post: results.data, + }; +}; + export const getSettings = async () => { const res = await api.settings.fetch(); if (res.success) {