-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Experiment w/ server islands and content layer * ⬆️ Astro 5.0 beta * ✨ Migrate Blog Posts to Content Layer API * ✨ Continue the Content Layer API Migration * ✨ Migrate to astro-icon * ⬇️ Back to 4x for now... * 🐛 Wrong path
- Loading branch information
Showing
37 changed files
with
3,518 additions
and
4,195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"astro.content-intellisense": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import { getCollection } from 'astro:content'; | ||
import { PostView, db, sql } from 'astro:db'; | ||
import { db, PostView, sql } from 'astro:db'; | ||
import { fromMarkdown } from 'mdast-util-from-markdown'; | ||
import { toString } from 'mdast-util-to-string'; | ||
import { readdir, readFile } from 'node:fs/promises'; | ||
|
||
export default async function () { | ||
const posts = await getCollection('posts'); | ||
const postsSearches = posts | ||
.map((post) => ({ slug: post.slug, body: toString(fromMarkdown(post.body), { includeHtml: false }) })) | ||
.map((post) => sql`(${post.slug}, ${post.body.replaceAll('\n', ' ')})`); | ||
const postsFileNames = await readdir('src/data/posts', { withFileTypes: true }); | ||
const postsContents = await Promise.all( | ||
postsFileNames.map(async (file) => { | ||
const post = (await readFile(`src/data/posts/${file.name}`, 'utf-8')).replace(/---[\s\S]*?---/, ''); | ||
const body = toString(fromMarkdown(post), { includeHtml: false }).replaceAll('\n', ' '); | ||
return sql`(${file.name.replace(/\.mdx$/, '')}, ${body})`; | ||
}), | ||
); | ||
|
||
await db.batch([ | ||
db.insert(PostView).values(posts.map((post) => ({ post: post.slug }))), | ||
db.insert(PostView).values(postsFileNames.map((post) => ({ post: post.name.replace(/\.mdx$/, '') }))), | ||
db.run(sql`drop table if exists PostSearch`), | ||
db.run(sql`create virtual table PostSearch using fts5(slug unindexed, body)`), | ||
db.run(sql.join([sql`insert into PostSearch (slug, body) values `, sql.join(postsSearches, sql`,`)])), | ||
db.run(sql.join([sql`insert into PostSearch (slug, body) values `, sql.join(postsContents, sql`,`)])), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.