Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";

import sitemap from "@astrojs/sitemap";
import mdx from "@astrojs/mdx";

export default defineConfig({
site: "https://esafev.com",
output: "static",
markdown: {
processor: unified(),
},
integrations: [sitemap(), mdx()]
});
505 changes: 280 additions & 225 deletions bun.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"note:create": "bun scripts/create-note"
},
"dependencies": {
"@astrojs/mdx": "^4.3.3",
"@astrojs/rss": "^4.0.12",
"@astrojs/sitemap": "^3.4.2",
"astro": "^5.12.8",
"sharp": "^0.34.2"
"@astrojs/mdx": "^7.0.0",
"@astrojs/rss": "^4.0.19",
"@astrojs/sitemap": "^3.7.3",
"astro": "^7.0.4",
"sharp": "^0.35.3"
},
"devDependencies": {
"@types/bun": "^1.2.20",
"typescript": "^5.9.2"
"@types/bun": "^1.3.14",
"typescript": "^6.0.3"
}
}
17 changes: 10 additions & 7 deletions src/components/NotePreview.astro
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
---
import type { Note } from '@/types/note';
import { formatDate } from '@/lib/date';
import { getNoteSlug } from '@/lib/notes';

export interface Props {
note: Note;
}

const {
note: {
slug,
data: {
title,
pubDate
}
}
note,
} = Astro.props;

const {
data: {
title,
pubDate
}
} = note;
const slug = getNoteSlug(note);
---

<section>
Expand Down
11 changes: 8 additions & 3 deletions src/content/config.ts → src/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { defineCollection, z } from 'astro:content';
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const notes = defineCollection({
type: 'content',
loader: glob({
base: './src/content/notes',
pattern: '**/*.{md,mdx}',
}),
schema: z.object({
title: z.string(),
description: z.string(),
Expand All @@ -13,4 +18,4 @@ const notes = defineCollection({

export const collections = {
notes,
};
};
8 changes: 6 additions & 2 deletions src/lib/notes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getCollection } from 'astro:content';
import { getCollection, type CollectionEntry } from 'astro:content';

function getNoteSlug(note: CollectionEntry<'notes'>) {
return note.data.slug ?? note.id;
}

async function getNotes() {
const notes = await getCollection('notes');
Expand All @@ -11,4 +15,4 @@ async function getNotes() {
});
}

export { getNotes };
export { getNotes, getNoteSlug };
12 changes: 7 additions & 5 deletions src/pages/notes/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
import NoteLayout from '@/layouts/NoteLayout.astro';
import { getNoteSlug } from '@/lib/notes';

export async function getStaticPaths() {
const notes = await getCollection('notes');
return notes.map((note) => ({
params: { slug: note.slug },
params: { slug: getNoteSlug(note) },
props: note,
}));
}

const note = Astro.props;
const { Content } = await note.render();
const slug = getNoteSlug(note);
const { Content } = await render(note);
---

<NoteLayout frontmatter={note.data} slug={note.slug}>
<NoteLayout frontmatter={note.data} {slug}>
<Content />
</NoteLayout>
</NoteLayout>
10 changes: 7 additions & 3 deletions src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type { APIRoute } from 'astro';

const siteURL = 'https://esafev.com';

function getTXT({ sitemapURL }: { sitemapURL: URL }) {
const lines = [
`User-agent: *`,
Expand All @@ -8,7 +12,7 @@ function getTXT({ sitemapURL }: { sitemapURL: URL }) {
return lines.join('\n');
}

export function GET({ site }): Response {
const sitemapURL = new URL('sitemap-index.xml', site);
export const GET: APIRoute = ({ site }) => {
const sitemapURL = new URL('sitemap-index.xml', site ?? siteURL);
return new Response(getTXT({ sitemapURL }));
}
};
36 changes: 29 additions & 7 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import rss from "@astrojs/rss";
import type { APIRoute } from "astro";
import { render } from "astro:content";
import { experimental_AstroContainer } from "astro/container";
import mdxRenderer from "@astrojs/mdx/server.js";

import { getNotes } from "@/lib/notes";
import { getNotes, getNoteSlug } from "@/lib/notes";

const container = await experimental_AstroContainer.create();
const siteURL = "https://esafev.com";
const markdownDeprecationWarning = "`markdown.gfm` and `markdown.smartypants` are deprecated";

async function createContainer() {
const warn = console.warn;
console.warn = (...args) => {
if (typeof args[0] === "string" && args[0].includes(markdownDeprecationWarning)) {
return;
}

warn(...args);
};

try {
return await experimental_AstroContainer.create();
} finally {
console.warn = warn;
}
}

const container = await createContainer();
container.addServerRenderer({ renderer: mdxRenderer, name: 'mdx' });

export async function GET({ site }) {
export const GET: APIRoute = async ({ site }) => {
const notes = await getNotes();
return rss({
title: "Vlad Esafev",
description: "Not causing trouble, not touching anything, fixing the primus",
site,
site: site ?? siteURL,
items: await Promise.all(
notes.map(async (note) => {
const { Content } = await note.render();
const { Content } = await render(note);
const htmlContent = await container.renderToString(Content);

return {
link: `notes/${note.slug}`,
link: `notes/${getNoteSlug(note)}`,
title: note.data.title,
description: note.data.description,
pubDate: note.data.pubDate,
Expand All @@ -28,4 +50,4 @@ export async function GET({ site }) {
})
),
});
}
};
4 changes: 2 additions & 2 deletions src/styles/global.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@font-face {
font-family: "IBM Plex Mono";
src: url("../../fonts/IBMPlexMono-Regular.woff2") format("woff2");
src: url("/fonts/IBMPlexMono-Regular.woff2") format("woff2");
font-weight: 400;
font-display: fallback;
}

@font-face {
font-family: "IBM Plex Mono";
src: url("../../fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
src: url("/fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
font-weight: 700;
font-display: fallback;
}
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"types": ["vite/client", "@types/bun"],
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
"@/*": ["./src/*"]
}
},
"include": [".astro/types.d.ts", "**/*"]
Expand Down
Loading