refactor: move pubDate to date in posts front matter
This commit is contained in:
parent
123da1747f
commit
b2270003bd
15 changed files with 21 additions and 22 deletions
|
@ -10,7 +10,7 @@ const lang = getLangFromUrl(Astro.url);
|
|||
const t = useTranslations(lang);
|
||||
const translatePath = useTranslatedPath(lang);
|
||||
const posts = await getCollection('posts');
|
||||
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
|
||||
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
||||
---
|
||||
|
||||
<Layout title="Blog Posts" description="List all posts on the website.">
|
||||
|
|
|
@ -34,7 +34,7 @@ const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.dat
|
|||
const wordcount = remarkPluginFrontmatter.wordcount;
|
||||
const lastUpdated = remarkPluginFrontmatter.lastModified;
|
||||
|
||||
const pubDate = new Date(entry.data.pubDate).toISOString().split('T')[0]
|
||||
const pubDate = new Date(entry.data.date).toISOString().split('T')[0]
|
||||
const lastUpdatedDate = new Date(lastUpdated).toISOString().split('T')[0]
|
||||
|
||||
// Get author data
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function GET({ props }) {
|
|||
const { entry } = props;
|
||||
// Format the content as plain text
|
||||
const title = entry.data.title;
|
||||
const date = entry.data.pubDate.toISOString().split('T')[0];
|
||||
const date = entry.data.date.toISOString().split('T')[0];
|
||||
const content = entry.body;
|
||||
|
||||
// Combine the post info and body into a single text file
|
||||
|
|
|
@ -19,10 +19,10 @@ ${await generateMarkdownSection("pages", "Page", baseUrl)}`;
|
|||
async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) {
|
||||
const items = await getCollection(collectionName);
|
||||
|
||||
// Sort posts by pubDate if available
|
||||
// Sort posts by date if available
|
||||
const sortedItems =
|
||||
collectionName === "posts"
|
||||
? items.sort((a, b) => (a.data.pubDate > b.data.pubDate ? -1 : 1))
|
||||
? items.sort((a, b) => (a.data.date > b.data.date ? -1 : 1))
|
||||
: items;
|
||||
|
||||
let markdown = `## ${sectionTitle}\n`;
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function GET(context) {
|
|||
// Load the content collection entries to add to our RSS feed.
|
||||
const posts = (await getCollection("posts")).sort((a, b) =>
|
||||
// Sort by publication date descending.
|
||||
a.data.pubDate > b.data.pubDate ? -1 : 1
|
||||
a.data.date > b.data.date ? -1 : 1
|
||||
);
|
||||
|
||||
// Loop over blog posts to create feed items for each, including full content.
|
||||
|
@ -57,7 +57,7 @@ export async function GET(context) {
|
|||
feedItems.push({
|
||||
title: post.data.title,
|
||||
description: post.data.description || '',
|
||||
pubDate: post.data.pubDate,
|
||||
date: post.data.date,
|
||||
link: `${baseUrl}/blog/${post.slug}`,
|
||||
content,
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ export async function GET() {
|
|||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
content: post.body,
|
||||
pubDate: post.data.pubDate,
|
||||
date: post.data.date,
|
||||
slug: post.slug
|
||||
}));
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ import { getCollection } from 'astro:content';
|
|||
export async function GET(context) {
|
||||
const posts = await getCollection('posts');
|
||||
// Sort posts by date (newest first)
|
||||
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
|
||||
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
||||
|
||||
const twtxt = posts.map(post => (
|
||||
`${new Date(post.data.pubDate).toISOString()}\t${post.data.title} ${context.site}blog/${post.slug}`
|
||||
`${new Date(post.data.date).toISOString()}\t${post.data.title} ${context.site}blog/${post.slug}`
|
||||
)).join('\n');
|
||||
|
||||
return new Response(twtxt, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue