mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
update: migrate from content.ts to content.config.ts
This commit is contained in:
parent
9cfd0cb049
commit
4c8dff619e
10 changed files with 302 additions and 329 deletions
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
import { defaultLocale, moreLocales } from '@/config'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getCollection } from 'astro:content'
|
||||
import { getCollection, render } from 'astro:content'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
type PathItem = {
|
||||
|
@ -34,7 +34,7 @@ const { lang } = Astro.props
|
|||
const allAboutEntries = await getCollection('about')
|
||||
const aboutEntry = allAboutEntries.find(entry => entry.data.lang === lang)
|
||||
|| allAboutEntries.find(entry => entry.data.lang === '')
|
||||
const { Content } = aboutEntry ? await aboutEntry.render() : { Content: null }
|
||||
const { Content } = aboutEntry ? await render(aboutEntry) : { Content: null }
|
||||
---
|
||||
|
||||
<Layout>
|
||||
|
|
|
@ -9,7 +9,7 @@ import { getTagPath } from '@/i18n/path'
|
|||
import Layout from '@/layouts/Layout.astro'
|
||||
import { checkPostSlugDuplication } from '@/utils/content'
|
||||
import { generateDescription } from '@/utils/description'
|
||||
import { getCollection } from 'astro:content'
|
||||
import { getCollection, render } from 'astro:content'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('posts')
|
||||
|
@ -24,7 +24,7 @@ export async function getStaticPaths() {
|
|||
// Use a Map to store the relationship between post slugs and their supported languages
|
||||
// Set is used to store the supported languages for each post
|
||||
const slugToLangsMap = posts.reduce((map, post) => {
|
||||
const slug = post.data.abbrlink || post.slug
|
||||
const slug = post.data.abbrlink || post.id
|
||||
const lang = post.data.lang
|
||||
|
||||
if (!map.has(slug)) {
|
||||
|
@ -58,7 +58,7 @@ export async function getStaticPaths() {
|
|||
posts.forEach((post: CollectionEntry<'posts'>) => {
|
||||
// Show drafts in dev mode only
|
||||
if (import.meta.env.DEV || !post.data.draft) {
|
||||
const slug = post.data.abbrlink || post.slug
|
||||
const slug = post.data.abbrlink || post.id
|
||||
const lang = post.data.lang
|
||||
|
||||
if (lang === defaultLocale || lang === '') {
|
||||
|
@ -79,7 +79,7 @@ export async function getStaticPaths() {
|
|||
posts.forEach((post: CollectionEntry<'posts'>) => {
|
||||
// Process posts with matching language or no language specified
|
||||
if ((import.meta.env.DEV || !post.data.draft) && (post.data.lang === lang || post.data.lang === '')) {
|
||||
const slug = post.data.abbrlink || post.slug
|
||||
const slug = post.data.abbrlink || post.id
|
||||
paths.push({
|
||||
params: { posts_slug: `${lang}/posts/${slug}/` },
|
||||
props: {
|
||||
|
@ -97,13 +97,13 @@ export async function getStaticPaths() {
|
|||
|
||||
const { post, lang, supportedLangs } = Astro.props
|
||||
const description = generateDescription(post, 'meta')
|
||||
const { Content, headings, remarkPluginFrontmatter } = await post.render()
|
||||
const { Content, headings, remarkPluginFrontmatter } = await render(post)
|
||||
---
|
||||
|
||||
<Layout
|
||||
postTitle={post.data.title}
|
||||
postDescription={description}
|
||||
postSlug={post.slug}
|
||||
postSlug={post.id}
|
||||
supportedLangs={supportedLangs}
|
||||
>
|
||||
<article class="heti mb-12.6">
|
||||
|
@ -113,7 +113,7 @@ const { Content, headings, remarkPluginFrontmatter } = await post.render()
|
|||
<!-- Title -->
|
||||
<h1 class="post-title">
|
||||
<span
|
||||
transition:name={`post-${post.data.abbrlink || post.slug}-${lang}`}
|
||||
transition:name={`post-${post.data.abbrlink || post.id}-${lang}`}
|
||||
data-disable-transition-on-theme
|
||||
>
|
||||
{post.data.title}
|
||||
|
@ -124,7 +124,7 @@ const { Content, headings, remarkPluginFrontmatter } = await post.render()
|
|||
<!-- Date -->
|
||||
<div
|
||||
class="mb-16.3 block c-primary font-time"
|
||||
transition:name={`time-${post.data.abbrlink || post.slug}-${lang}`}
|
||||
transition:name={`time-${post.data.abbrlink || post.id}-${lang}`}
|
||||
data-disable-transition-on-theme
|
||||
>
|
||||
<PostDate
|
||||
|
|
|
@ -9,7 +9,7 @@ const blogEntries = await getCollection('posts')
|
|||
// Convert blog entries into a lookup object with slug as key and title/description as value
|
||||
const pages = Object.fromEntries(
|
||||
blogEntries.map((post: CollectionEntry<'posts'>) => [
|
||||
post.slug,
|
||||
post.id,
|
||||
{
|
||||
title: post.data.title,
|
||||
description: post.data.description || generateDescription(post, 'og'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue