mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
feat: support custom canonical URLs (#83)
Adding an optional attribute in the posts' frontmatter that allows the user to set a custom canonical URL
This commit is contained in:
committed by
Sat Naing
parent
08383093d1
commit
4687bd516b
@@ -9,6 +9,7 @@ export interface Props {
|
||||
author?: string;
|
||||
description?: string;
|
||||
ogImage?: string;
|
||||
canonicalURL?: string;
|
||||
}
|
||||
|
||||
const {
|
||||
@@ -16,10 +17,9 @@ const {
|
||||
author = SITE.author,
|
||||
description = SITE.desc,
|
||||
ogImage = SITE.ogImage,
|
||||
canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
|
||||
} = Astro.props;
|
||||
|
||||
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
|
||||
|
||||
const socialImageURL = new URL(
|
||||
ogImage ? ogImage : SITE.ogImage,
|
||||
Astro.url.origin
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface Props {
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
const { title, author, description, ogImage, pubDatetime, tags } = post.data;
|
||||
const { title, author, description, ogImage, canonicalURL, pubDatetime, tags } = post.data;
|
||||
|
||||
const { Content } = await post.render();
|
||||
|
||||
@@ -21,7 +21,7 @@ const ogUrl = new URL(ogImage ? ogImage : `${title}.png`, Astro.url.origin)
|
||||
.href;
|
||||
---
|
||||
|
||||
<Layout title={title} author={author} description={description} ogImage={ogUrl}>
|
||||
<Layout title={title} author={author} description={description} ogImage={ogUrl} canonicalURL={canonicalURL}>
|
||||
<Header />
|
||||
<div class="mx-auto flex w-full max-w-3xl justify-start px-2">
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user