Skip to content

Commit

Permalink
feat: 使用 originalUrl 地址
Browse files Browse the repository at this point in the history
  • Loading branch information
songxingguo committed Jun 5, 2024
1 parent f9572d0 commit a026015
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ declare module 'astro:content' {
collection: "posts";
data: InferEntrySchema<"posts">
} & { render(): Render[".md"] };
"多媒体前端手册.md": {
id: "多媒体前端手册.md";
slug: "多媒体前端手册";
body: string;
collection: "posts";
data: InferEntrySchema<"posts">
} & { render(): Render[".md"] };
"如何将语雀文章发布到Hexo博客.md": {
id: "如何将语雀文章发布到Hexo博客.md";
slug: "如何将语雀文章发布到hexo博客";
Expand Down
11 changes: 5 additions & 6 deletions src/components/Link.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
---
interface Props {
href: string;
original?: string;
originalPath?: string;
originalUrl?: string;
}
const { href, original, originalPath } = Astro.props;
const url = !original
? href
: `https://${original}.songxingguo.com/${originalPath}`;
const { href, originalUrl } = Astro.props;
const host = originalUrl?.split("/")[2] || ""; // 获取域名地址
const original = host.split(".").slice(0, -2).join("."); //获取子域名
const url = !original ? href : originalUrl;
---

<a href={url}
Expand Down
7 changes: 3 additions & 4 deletions src/components/ListItem.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ interface Props {
href: string;
title?: string;
description?: string;
original?: string;
originalPath?: string;
originalUrl?: string;
}
const { href, title, description, original, originalPath } = Astro.props;
const { href, title, description, originalUrl } = Astro.props;
---

<li un-flex="~ col gap-1 items-start">
<h3 class="post-title!">
<Link href={href} original={original} originalPath={originalPath}>
<Link href={href} originalUrl={originalUrl}>
{title}
</Link>
</h3>
Expand Down
6 changes: 1 addition & 5 deletions src/components/Post.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const { translate: t } = Astro.locals;
<article class="heti">
<header>
<h1 class="post-title!">
<Link
href=`/posts/${post.slug}/`
original={post.data.original}
originalPath={post.data.originalPath}
>
<Link href=`/posts/${post.slug}/` originalUrl={post.data.originalUrl}>
{post.data.title}
</Link>
</h1>
Expand Down
3 changes: 1 addition & 2 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const posts = defineCollection({
enclosure: z.optional(
z.object({ url: z.string(), length: z.number(), type: z.string() })
),
original: z.string().optional(),
originalPath: z.string().optional(),
originalUrl: z.string().optional(),
}),
});

Expand Down
3 changes: 1 addition & 2 deletions src/pages/archive.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ posts.forEach((post: Post) => {
title={post.data.title}
href={`/posts/${post.slug}/`}
description={formatDate(post.data.date)}
original={post.data.original}
originalPath={post.data.originalPath}
originalUrl={post.data.originalUrl}
/>
))}
</ListSection>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/categories/[...category].astro
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const { name } = Astro.params;
title={post.data.title}
href={`/posts/${post.slug}/`}
description={formatDate(post.data.date)}
original={post.data.original}
originalPath={post.data.originalPath}
originalUrl={post.data.originalUrl}
/>
))
}
Expand Down

0 comments on commit a026015

Please sign in to comment.