Merge pull request #1 from conglinyizhi/master

This commit is contained in:
草方块 2025-05-18 12:31:28 +08:00 committed by GitHub
commit d33b2be49e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 4 deletions

View file

@ -10,7 +10,7 @@ interface Props {
title: string; title: string;
description: string; description: string;
path?: string; path?: string;
ogImage: string; ogImage?: string;
} }
const defaultTitle = siteConfig.title const defaultTitle = siteConfig.title

25
src/pages/404.astro Normal file
View file

@ -0,0 +1,25 @@
---
import Layout from '../layouts/Layout.astro';
const url = Astro.url.pathname
---
<Layout title="404 | Terminal Blog" description="Page not found">
<h1 class="title">command not found.</h1>
<div class="content">
<p class="typewriter">sh: <span class="path">~{url}</span>: command not found.</p>
<div style="margin-top: 2rem;">
<span class="command">help</span>
<div style="margin-top: 1rem; margin-left: 1rem;">
<p>
Looks like this is an unknown command or file, try:
</p>
<p>
<a href="/">Return to Home</a>
</p>
</div>
</div>
</div>
</Layout>

View file

@ -6,7 +6,7 @@ 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.pubDate).getTime() - new Date(a.data.pubDate).getTime());
--- ---
<Layout title="Blog | Terminal Blog"> <Layout title="Blog | Terminal Blog" description="List all files and folders in the directory.">
<h1 class="title">~/blog</h1> <h1 class="title">~/blog</h1>
<div class="content"> <div class="content">

View file

@ -3,10 +3,11 @@ import Layout from '../layouts/Layout.astro';
--- ---
<Layout title="Home | Terminal Blog"> <Layout title="Home | Terminal Blog" description="That a good start.">
<h1 class="title">~/</h1> <h1 class="title">~/</h1>
<div class="content"> <div class="content">
<h3>Welcome!</h3>
Not much here yet, but you can check out my blog posts <a href="/blog">here</a>. Not much here yet, but you can check out my blog posts <a href="/blog">here</a>.
<br /> <br />
If you are site owner, please edit <code>src/pages/index.astro</code> to customize this page. If you are site owner, please edit <code>src/pages/index.astro</code> to customize this page.

42
src/pages/llms.txt.js Normal file
View file

@ -0,0 +1,42 @@
import { getCollection } from "astro:content";
import { siteConfig } from "../config";
// Modified version that outputs markdown content
export async function GET(context) {
let baseUrl = context.site?.href || "https://terminal-blog.example.com";
if (baseUrl.at(-1) === "/") baseUrl = baseUrl.slice(0, -1);
const markdownText = `# ${siteConfig.title}
> ${siteConfig.description}
${await generateMarkdownSection("posts", "Post", baseUrl)}
${await generateMarkdownSection("pages", "Page", baseUrl)}`;
return new Response(markdownText);
}
async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) {
const items = await getCollection(collectionName);
// Sort posts by pubDate if available
const sortedItems =
collectionName === "posts"
? items.sort((a, b) => (a.data.pubDate > b.data.pubDate ? -1 : 1))
: items;
let markdown = `## ${sectionTitle}\n`;
for (const item of sortedItems) {
const { title, description, slug } = getMetaData(item);
markdown += `\n- [${title}](${baseUrl}/post/${slug}): ${description}`;
}
return markdown;
}
function getMetaData(collection) {
const { title, description } = collection.data;
const { slug } = collection;
return { title, description, slug };
}