Skip to content

Commit 2774045

Browse files
authored
fix: broken editPost link and update editPost logic (#487)
* fix: broken editPost link and update editPost logic Fixed broken editPost link. Removed the ability to update the editPost link inside each blog post for consistency. The editPost button per blog post can still be hidden. * docs: update docs for editPost
1 parent 48f200f commit 2774045

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

src/components/EditPost.astro

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import IconEdit from "@/assets/icons/IconEdit.svg";
44
import { SITE } from "@/config";
55
66
export interface Props {
7-
editPost?: CollectionEntry<"blog">["data"]["editPost"];
8-
postId?: CollectionEntry<"blog">["id"];
7+
hideEditPost?: CollectionEntry<"blog">["data"]["hideEditPost"];
98
class?: string;
9+
post: CollectionEntry<"blog">;
1010
}
1111
12-
const { editPost, postId, class: className = "" } = Astro.props;
12+
const { hideEditPost, post, class: className = "" } = Astro.props;
1313
14-
let editPostUrl = editPost?.url ?? SITE?.editPost?.url ?? "";
15-
const showEditPost = !editPost?.disabled && editPostUrl.length > 0;
16-
const appendFilePath =
17-
editPost?.appendFilePath ?? SITE?.editPost?.appendFilePath ?? false;
18-
if (appendFilePath && postId) {
19-
editPostUrl += `/${postId}`;
20-
}
21-
const editPostText = editPost?.text ?? SITE?.editPost?.text ?? "Edit";
14+
const href = `${SITE.editPost.url}${post.filePath}`;
15+
const showEditPost =
16+
SITE.editPost.enabled && !hideEditPost && href.trim() !== "";
2217
---
2318

2419
{
@@ -29,12 +24,14 @@ const editPostText = editPost?.text ?? SITE?.editPost?.text ?? "Edit";
2924
</span>
3025
<a
3126
class="space-x-1.5 hover:opacity-75"
32-
href={editPostUrl}
27+
href={href}
3328
rel="noopener noreferrer"
3429
target="_blank"
3530
>
3631
<IconEdit class="inline-block size-6" />
37-
<span class="italic max-sm:text-sm sm:inline">{editPostText}</span>
32+
<span class="italic max-sm:text-sm sm:inline">
33+
{SITE.editPost.text}
34+
</span>
3835
</a>
3936
</div>
4037
)

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export const SITE = {
1212
showArchives: true,
1313
showBackButton: true, // show back button in post detail
1414
editPost: {
15-
url: "https://github.com/satnaing/astro-paper/edit/main/src/data/blog",
15+
enabled: true,
1616
text: "Suggest Changes",
17-
appendFilePath: true,
17+
url: "https://github.com/satnaing/astro-paper/edit/main/",
1818
},
1919
dynamicOgImage: true,
2020
} as const;

src/content.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ const blog = defineCollection({
1818
ogImage: image().or(z.string()).optional(),
1919
description: z.string(),
2020
canonicalURL: z.string().optional(),
21-
editPost: z
22-
.object({
23-
disabled: z.boolean().optional(),
24-
url: z.string().optional(),
25-
text: z.string().optional(),
26-
appendFilePath: z.boolean().optional(),
27-
})
28-
.optional(),
21+
hideEditPost: z.boolean().optional(),
2922
}),
3023
});
3124

src/data/blog/adding-new-post.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: Sat Naing
33
pubDatetime: 2022-09-23T15:22:00Z
4-
modDatetime: 2025-03-17T17:41:19.776Z
4+
modDatetime: 2025-03-20T03:22:19.075Z
55
title: Adding new posts in AstroPaper theme
66
slug: adding-new-posts-in-astropaper-theme
77
featured: true
@@ -71,6 +71,7 @@ Here is the list of frontmatter property for each post.
7171
| **_tags_** | Related keywords for this post. Written in array yaml format. | default = others |
7272
| **_ogImage_** | OG image of the post. Useful for social media sharing and SEO. This can be a remote URL or an image path relative to current folder. | default = `SITE.ogImage` or generated OG image |
7373
| **_canonicalURL_** | Canonical URL (absolute), in case the article already exists on other source. | default = `Astro.site` + `Astro.url.pathname` |
74+
| **_hideEditPost_** | Hide editPost button under blog title. This applies only to the current blog post. | default = false |
7475

7576
> Tip! You can get ISO 8601 datetime by running `new Date().toISOString()` in the console. Make sure you remove quotes though.
7677

src/data/blog/how-to-configure-astropaper-theme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: Sat Naing
33
pubDatetime: 2022-09-23T04:58:53Z
4-
modDatetime: 2025-03-12T13:39:39.057Z
4+
modDatetime: 2025-03-20T03:15:57.792Z
55
title: How to configure AstroPaper theme
66
slug: how-to-configure-astropaper-theme
77
featured: true
@@ -38,9 +38,9 @@ export const SITE = {
3838
showArchives: true,
3939
showBackButton: true, // show back button in post detail
4040
editPost: {
41-
url: "https://github.com/satnaing/astro-paper/edit/main/src/content/blog",
41+
enabled: true,
4242
text: "Suggest Changes",
43-
appendFilePath: true,
43+
url: "https://github.com/satnaing/astro-paper/edit/main/",
4444
},
4545
dynamicOgImage: true, // enable automatic dynamic og-image generation
4646
} as const;
@@ -62,7 +62,7 @@ Here are SITE configuration options
6262
| `scheduledPostMargin` | In Production mode, posts with a future `pubDatetime` will not be visible. However, if a post's `pubDatetime` is within the next 15 minutes, it will be visible. You can set `scheduledPostMargin` if you don't like the default 15 minutes margin. |
6363
| `showArchives` | Determines whether to display the `Archives` menu (positioned between the `About` and `Search` menus) and its corresponding page on the site. This option is set to `true` by default. |
6464
| `showBackButton` | Determines whether to display the `Go back` button in each blog post. |
65-
| `editPost` | This option allows users to suggest changes to a blog post by providing an edit link under blog post titles. This feature can be disabled by removing it from the `SITE` config. You can also set `appendFilePath` to `true` to automatically append the file path of the post to the url, directing users to the specific post they wish to edit. |
65+
| `editPost` | This option allows users to suggest changes to a blog post by providing an edit link under blog post titles. This feature can be disabled by setting `SITE.editPost.enabled` to `false`. |
6666
| `dynamicOgImage` | This option controls whether to [generate dynamic og-image](https://astro-paper.pages.dev/posts/dynamic-og-image-generation-in-astropaper-blog-posts/) if no `ogImage` is specified in the blog post frontmatter. If you have many blog posts, you might want to disable this feature. See the [trade-off](https://astro-paper.pages.dev/posts/dynamic-og-image-generation-in-astropaper-blog-posts/#trade-off) for more details. |
6767

6868
## Configuring locale

src/layouts/PostDetails.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const {
3030
pubDatetime,
3131
modDatetime,
3232
tags,
33-
editPost,
33+
hideEditPost,
3434
} = post.data;
3535
3636
const { Content } = await render(post);
@@ -103,15 +103,15 @@ const nextPost =
103103
size="lg"
104104
class="my-2"
105105
/>
106-
<EditPost class="max-sm:hidden" editPost={editPost} postId={post.id} />
106+
<EditPost class="max-sm:hidden" {hideEditPost} {post} />
107107
</div>
108108
<article id="article" class="mx-auto prose mt-8 max-w-3xl">
109109
<Content />
110110
</article>
111111

112112
<hr class="my-8 border-dashed" />
113113

114-
<EditPost class="sm:hidden" editPost={editPost} postId={post.id} />
114+
<EditPost class="sm:hidden" {hideEditPost} {post} />
115115

116116
<ul class="mt-4 mb-8 sm:my-8">
117117
{tags.map(tag => <Tag tag={slugifyStr(tag)} tagName={tag} />)}

0 commit comments

Comments
 (0)