Skip to content

Commit

Permalink
feat: add post pages
Browse files Browse the repository at this point in the history
  • Loading branch information
roushou committed Nov 11, 2024
1 parent c58e960 commit 483e057
Show file tree
Hide file tree
Showing 19 changed files with 1,477 additions and 5 deletions.
3 changes: 2 additions & 1 deletion astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import cloudflare from "@astrojs/cloudflare";
import mdx from "@astrojs/mdx";
import solidJs from "@astrojs/solid-js";
import tailwind from "@astrojs/tailwind";
import icon from "astro-icon";
import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
integrations: [solidJs(), tailwind(), icon()],
integrations: [mdx(), solidJs(), tailwind(), icon()],
output: "hybrid",
adapter: cloudflare(),
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@astrojs/cloudflare": "^11.0.4",
"@astrojs/mdx": "^3.1.9",
"@astrojs/solid-js": "^4.4.0",
"astro": "^4.13.2",
"astro-icon": "^1.1.0",
Expand All @@ -27,6 +28,7 @@
"@astrojs/check": "^0.9.2",
"@astrojs/tailwind": "^5.1.0",
"@biomejs/biome": "^1.8.3",
"@tailwindcss/typography": "^0.5.15",
"typescript": "^5.5.4"
},
"packageManager": "[email protected]"
Expand Down
723 changes: 722 additions & 1 deletion pnpm-lock.yaml

Large diffs are not rendered by default.

Binary file added public/assets/images/mined/basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/images/mined/cloudrun-step.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/images/mined/its-a-server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/images/mined/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/images/mined/vm-step.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/fonts/Nunito.ttf
Binary file not shown.
71 changes: 71 additions & 0 deletions src/components/toc.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
import type { MarkdownHeading } from "astro";
type Props = {
headings: MarkdownHeading[];
// The depth of the headings to display.
depth: number;
class?: string;
};
const props = Astro.props;
type TocHeading = MarkdownHeading & {
subHeadings: MarkdownHeading[];
};
/**
Format headings into a nested structure. Note it works correctly only for depth 2 and 3.
*/
function formatHeadings({
headings,
depth,
}: { headings: MarkdownHeading[]; depth: number }): TocHeading[] | undefined {
const toc: TocHeading[] = [];
for (const heading of headings) {
if (depth < heading.depth) return;
if (heading.depth === 2) {
toc.push({ ...heading, subHeadings: [] });
return;
}
toc[toc.length - 1].subHeadings.push(heading);
}
return toc;
}
const headings = formatHeadings({
headings: props.headings,
depth: props.depth,
});
---

<aside class:list={["font-nunito", props.class]}>
<ul class="w-56 list-none">
{
headings?.map((heading) => (
<li>
<a
href={`#${heading.slug}`}
class="w-full text-sm text-gray-300 no-underline hover:text-indigo-500"
>
{heading.text}
</a>
{heading.subHeadings.length > 0 ? (
<ul class="flex list-none flex-col space-y-1">
{heading.subHeadings.map((subHeading: MarkdownHeading) => (
<a
href={`#${subHeading.slug}`}
class="w-full pl-6 text-sm text-gray-300 no-underline hover:text-indigo-500"
>
{subHeading.text}
</a>
))}
</ul>
) : null}
</li>
))
}
</ul>
</aside>
23 changes: 23 additions & 0 deletions src/components/topbar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ const { pathname } = Astro.url;
<span>Home</span>
</a>
</li>
<li>
<a
href="/posts"
rel="prefetch"
class:list={[
"flex items-center space-x-2 bg-gray-900 px-4 py-1.5 border",
"2xl:text-lg",
"hover:text-indigo-500 hover:border-indigo-500",
{ "border-transparent": !pathname.startsWith("/posts") },
{ "text-indigo-500 border-indigo-500": pathname.startsWith("/posts") },
]}
>
<span class="h-2 w-2 bg-indigo-500"></span>
<span>Posts</span>
</a>
</li>
<li>
<a
href="/uses"
Expand Down Expand Up @@ -73,6 +89,13 @@ const { pathname } = Astro.url;
<span class:list={["text-2xl", { "text-amber-500": pathname === "/" }]}>Home</span>
</a>
</li>
<li>
<a href="/posts" class="flex h-16 items-center justify-center space-x-4">
<span class:list={["text-2xl", { "text-indigo-500": pathname.startsWith("/posts") }]}
>Posts</span
>
</a>
</li>
<li>
<a href="/uses" class="flex h-16 items-center justify-center space-x-4">
<span class:list={["text-2xl", { "text-orange-500": pathname.startsWith("/uses") }]}
Expand Down
18 changes: 18 additions & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-expect-error - Ignore missing types when the project has not been built e.g. CI environment

Check failure on line 1 in src/content/config.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unused '@ts-expect-error' directive.
import { defineCollection, z } from "astro:content";

const posts = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
description: z.string(),
author: z.literal("Roushou"),
date: z.date(),
draft: z.boolean(),
tags: z.array(z.string()),
}),
});

export const collections = {
posts,
};
Loading

0 comments on commit 483e057

Please sign in to comment.