@levino/shipyard-blog 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,6 @@ import Layout from "./Layout.astro";
3
3
  import { TableOfContents } from "@levino/shipyard-base/components";
4
4
  import { render, getCollection } from "astro:content";
5
5
 
6
- interface BlogData {
7
- title: string;
8
- description?: string;
9
- }
10
-
11
6
  export const getStaticPaths = async () => {
12
7
  const getParams = (slug: string) => {
13
8
  const [locale, ...rest] = slug.split("/");
@@ -16,7 +11,7 @@ export const getStaticPaths = async () => {
16
11
  locale,
17
12
  };
18
13
  };
19
- const blogPosts = await getCollection<BlogData>("blog");
14
+ const blogPosts = await getCollection("blog");
20
15
  return blogPosts.map((entry) => ({
21
16
  params: getParams(entry.id),
22
17
  props: { entry },
@@ -0,0 +1,39 @@
1
+ ---
2
+ import type { GetStaticPaths } from "astro";
3
+ import Layout from "./Layout.astro";
4
+ import { getCollection } from "astro:content";
5
+ import config from "virtual:shipyard/config";
6
+
7
+ export const getStaticPaths = (() =>
8
+ config.locales.map((locale) => ({
9
+ params: {
10
+ locale,
11
+ },
12
+ }))) satisfies GetStaticPaths;
13
+
14
+ const entries = await getCollection("blog").then((posts) =>
15
+ posts.toSorted((a, b) => b.data.date.getTime() - a.data.date.getTime()),
16
+ );
17
+
18
+ const getBlogPostLink = (id: string, locale: string) =>
19
+ id.replace(`${locale}/`, `${locale}/blog/`);
20
+
21
+ const { locale } = Astro.params;
22
+ const formatDate = new Intl.DateTimeFormat(locale).format;
23
+ ---
24
+
25
+ <Layout>
26
+ <div class="mx-auto max-w-prose px-8">
27
+ {
28
+ entries.map(async (entry) => (
29
+ <a class="block my-8" href={`/${getBlogPostLink(entry.id, locale)}`}>
30
+ <div class="prose">
31
+ <div class="text-sm">{formatDate(entry.data.date)}</div>
32
+ <h2 class="my-0">{entry.data.title}</h2>
33
+ <p>{entry.data.description}</p>
34
+ </div>
35
+ </a>
36
+ ))
37
+ }
38
+ </div>
39
+ </Layout>
@@ -2,8 +2,11 @@
2
2
  import { getCollection } from "astro:content";
3
3
  import { Page as BaseLayout } from "@levino/shipyard-base/layouts";
4
4
  const locale = Astro.currentLocale;
5
- const entry = await getCollection<{ title: string }>("blog").then(
6
- (collection) =>
5
+ const entry = await getCollection("blog")
6
+ .then((posts) =>
7
+ posts.toSorted((a, b) => b.data.date.getTime() - a.data.date.getTime()),
8
+ )
9
+ .then((collection) =>
7
10
  collection.reduce(
8
11
  (acc, { id, data: { title } }, key) => ({
9
12
  ...acc,
@@ -14,7 +17,7 @@ const entry = await getCollection<{ title: string }>("blog").then(
14
17
  }),
15
18
  {},
16
19
  ),
17
- );
20
+ );
18
21
  ---
19
22
 
20
23
  <BaseLayout sidebarNavigation={entry}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levino/shipyard-blog",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -17,7 +17,7 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@levino/shipyard-base": "^0.2.0"
20
+ "@levino/shipyard-base": "^0.4.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "astro": "^5"
package/src/astro.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default as BlogEntry } from './BlogEntry.astro'
2
- export { default as Layout } from './Layout.astro'
1
+ export { default as BlogEntry } from '../astro/BlogEntry.astro'
2
+ export { default as Layout } from '../astro/Layout.astro'
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { AstroIntegration } from 'astro'
4
4
  export const blogSchema = z.object({
5
5
  date: z.date(),
6
6
  title: z.string(),
7
+ description: z.string(),
7
8
  })
8
9
 
9
10
  export default (blogPaths: string[]): AstroIntegration => ({
@@ -11,6 +12,10 @@ export default (blogPaths: string[]): AstroIntegration => ({
11
12
  hooks: {
12
13
  'astro:config:setup': ({ injectRoute }) => {
13
14
  blogPaths.forEach((path) => {
15
+ injectRoute({
16
+ pattern: `/[locale]/${path}`,
17
+ entrypoint: `@levino/shipyard-blog/astro/BlogIndex.astro`,
18
+ })
14
19
  injectRoute({
15
20
  pattern: `/[locale]/${path}/[...slug]`,
16
21
  entrypoint: `@levino/shipyard-blog/astro/BlogEntry.astro`,