Skip to content

Commit 701d0dc

Browse files
committed
2024.10.29 Update to astro-paper v2.7
1 parent d69c785 commit 701d0dc

File tree

12 files changed

+575
-538
lines changed

12 files changed

+575
-538
lines changed

astro.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import react from "@astrojs/react";
44
import remarkToc from "remark-toc";
55
import remarkCollapse from "remark-collapse";
66
import sitemap from "@astrojs/sitemap";
7+
import { SITE } from "./src/config";
78

89
// https://astro.build/config
910
export default defineConfig({

package-lock.json

Lines changed: 451 additions & 525 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emeraldjava.github.io",
3-
"version": "2024.9.28",
3+
"version": "2024.10.29",
44
"scripts": {
55
"dev": "astro dev",
66
"start": "astro dev",
@@ -17,21 +17,21 @@
1717
"@astrojs/check": "^0.9.3",
1818
"@astrojs/rss": "^4.0.7",
1919
"@resvg/resvg-js": "^2.6.2",
20-
"astro": "^4.15.9",
21-
"cross-env": "^7.0.3",
20+
"astro": "^4.16.3",
2221
"fuse.js": "^7.0.0",
2322
"lodash.kebabcase": "^4.1.1",
2423
"remark-collapse": "^0.1.2",
2524
"remark-toc": "^9.0.0",
2625
"satori": "^0.11.0",
2726
"tailwindcss": "^3.4.11",
28-
"typescript": "^5.6.2"
27+
"typescript": "^5.5.3"
2928
},
3029
"devDependencies": {
3130
"@astrojs/react": "^3.6.2",
3231
"@astrojs/sitemap": "^3.1.6",
3332
"@astrojs/tailwind": "^5.1.0",
3433
"@tailwindcss/typography": "^0.5.15",
34+
"@types/github-slugger": "^1.3.0",
3535
"@types/lodash.kebabcase": "^4.1.9",
3636
"@types/react": "^18.3.6",
3737
"@typescript-eslint/parser": "^8.5.0",

src/components/Datetime.tsx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { LOCALE } from "@config";
1+
import { LOCALE, SITE } from "@config";
2+
import type { CollectionEntry } from "astro:content";
23

34
interface DatetimesProps {
45
pubDatetime: string | Date;
56
modDatetime: string | Date | undefined | null;
67
}
78

8-
interface Props extends DatetimesProps {
9+
interface EditPostProps {
10+
editPost?: CollectionEntry<"blog">["data"]["editPost"];
11+
postId?: CollectionEntry<"blog">["id"];
12+
}
13+
14+
interface Props extends DatetimesProps, EditPostProps {
915
size?: "sm" | "lg";
1016
className?: string;
1117
}
@@ -15,6 +21,8 @@ export default function Datetime({
1521
modDatetime,
1622
size = "sm",
1723
className = "",
24+
editPost,
25+
postId,
1826
}: Props) {
1927
return (
2028
<div
@@ -42,6 +50,7 @@ export default function Datetime({
4250
pubDatetime={pubDatetime}
4351
modDatetime={modDatetime}
4452
/>
53+
{size === "lg" && <EditPost editPost={editPost} postId={postId} />}
4554
</span>
4655
</div>
4756
);
@@ -72,3 +81,40 @@ const FormattedDatetime = ({ pubDatetime, modDatetime }: DatetimesProps) => {
7281
</>
7382
);
7483
};
84+
85+
const EditPost = ({ editPost, postId }: EditPostProps) => {
86+
let editPostUrl = editPost?.url ?? SITE?.editPost?.url ?? "";
87+
const showEditPost = !editPost?.disabled && editPostUrl.length > 0;
88+
const appendFilePath =
89+
editPost?.appendFilePath ?? SITE?.editPost?.appendFilePath ?? false;
90+
if (appendFilePath && postId) {
91+
editPostUrl += `/${postId}`;
92+
}
93+
const editPostText = editPost?.text ?? SITE?.editPost?.text ?? "Edit";
94+
95+
return (
96+
showEditPost && (
97+
<>
98+
<span aria-hidden="true"> | </span>
99+
<a
100+
className="space-x-1.5 hover:opacity-75"
101+
href={editPostUrl}
102+
rel="noopener noreferrer"
103+
target="_blank"
104+
>
105+
<svg
106+
xmlns="http://www.w3.org/2000/svg"
107+
className="icon icon-tabler icons-tabler-outline icon-tabler-edit inline-block !scale-90 fill-skin-base"
108+
aria-hidden="true"
109+
>
110+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
111+
<path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" />
112+
<path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
113+
<path d="M16 5l3 3" />
114+
</svg>
115+
<span className="text-base italic">{editPostText}</span>
116+
</a>
117+
</>
118+
)
119+
);
120+
};

src/components/Header.astro

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Hr from "./Hr.astro";
44
import LinkButton from "./LinkButton.astro";
55
66
export interface Props {
7-
activeNav?: "posts" | "tags" | "about" | "search";
7+
activeNav?: "posts" | "archives" | "tags" | "about" | "search";
88
}
99
1010
const { activeNav } = Astro.props;
@@ -70,6 +70,41 @@ const { activeNav } = Astro.props;
7070
About
7171
</a>
7272
</li>
73+
{
74+
SITE.showArchives && (
75+
<li>
76+
<LinkButton
77+
href="/archives/"
78+
className={`focus-outline flex justify-center p-3 sm:p-1`}
79+
ariaLabel="archives"
80+
title="Archives"
81+
>
82+
<svg
83+
xmlns="http://www.w3.org/2000/svg"
84+
class:list={[
85+
"icon icon-tabler icons-tabler-outline !hidden sm:!inline-block",
86+
activeNav === "archives" && "!stroke-skin-accent",
87+
]}
88+
>
89+
<>
90+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
91+
<path d="M3 4m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z" />
92+
<path d="M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-10" />
93+
<path d="M10 12l4 0" />
94+
</>
95+
</svg>
96+
<span
97+
class:list={[
98+
"sm:sr-only",
99+
activeNav === "archives" && "active",
100+
]}
101+
>
102+
Archives
103+
</span>
104+
</LinkButton>
105+
</li>
106+
)
107+
}
73108
<li>
74109
<LinkButton
75110
href="/search/"
@@ -155,7 +190,7 @@ const { activeNav } = Astro.props;
155190
nav ul li:nth-last-child(2) {
156191
@apply col-span-1;
157192
}
158-
nav a.active {
193+
nav .active {
159194
@apply underline decoration-wavy decoration-2 underline-offset-4;
160195
}
161196
nav a.active svg {

src/components/Search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function SearchBar({ searchList }: Props) {
5858
useEffect(() => {
5959
// Add search result only if
6060
// input value is more than one character
61-
let inputResult = inputVal.length > 1 ? fuse.search(inputVal) : [];
61+
const inputResult = inputVal.length > 1 ? fuse.search(inputVal) : [];
6262
setSearchResults(inputResult);
6363

6464
// Update search string in URL

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export const SITE: Site = {
1111
postPerIndex: 4,
1212
postPerPage: 3,
1313
scheduledPostMargin: 15 * 60 * 1000, // 15 minutes
14+
showArchives: true,
15+
editPost: {
16+
url: "https://github.com/satnaing/astro-paper/edit/main/src/content/blog",
17+
text: "Suggest Changes",
18+
appendFilePath: true,
19+
},
1420
};
1521

1622
export const LOCALE = {

src/content/config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { SITE } from "@config";
22
import { glob } from "astro/loaders";
33
import { defineCollection, z } from "astro:content";
44

5-
// see https://docs.astro.build/en/guides/content-c
6-
// ollections/#defining-a-collection-schema
5+
// see https://docs.astro.build/en/guides/content-collections/#defining-a-collection-schema
76
const blog = defineCollection({
8-
loader: glob({ pattern: "**/*.md", base: "./content/blog" }),
7+
type: "content_layer",
8+
loader: glob({ pattern: "**/*.md", base: "./src/content/blog" }),
99
schema: ({ image }) =>
1010
z.object({
1111
author: z.string().default(SITE.author),
@@ -23,6 +23,14 @@ const blog = defineCollection({
2323
.optional(),
2424
description: z.string(),
2525
canonicalURL: z.string().optional(),
26+
editPost: z
27+
.object({
28+
disabled: z.boolean().optional(),
29+
url: z.string().optional(),
30+
text: z.string().optional(),
31+
appendFilePath: z.boolean().optional(),
32+
})
33+
.optional(),
2634
}),
2735
});
2836

src/layouts/PostDetails.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
pubDatetime,
2626
modDatetime,
2727
tags,
28+
editPost,
2829
} = post.data;
2930
3031
const { Content } = await post.render();
@@ -82,6 +83,8 @@ const nextPost =
8283
modDatetime={modDatetime}
8384
size="lg"
8485
className="my-2"
86+
editPost={editPost}
87+
postId={post.id}
8588
/>
8689
<article id="article" class="prose mx-auto mt-8 max-w-3xl">
8790
<Content />

src/pages/posts/[...page].astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { SITE } from "@config";
33
import Posts from "@layouts/Posts.astro";
44
import type { GetStaticPaths } from "astro";
55
import { getCollection } from "astro:content";
6+
import getSortedPosts from "@utils/getSortedPosts";
67
78
export const getStaticPaths = (async ({ paginate }) => {
89
const posts = await getCollection("blog", ({ data }) => !data.draft);
9-
return paginate(posts, { pageSize: SITE.postPerPage });
10+
return paginate(getSortedPosts(posts), { pageSize: SITE.postPerPage });
1011
}) satisfies GetStaticPaths;
1112
1213
const { page } = Astro.props;

0 commit comments

Comments
 (0)