Skip to content

Commit

Permalink
Merge pull request #26 from hayato-osh/feature/seo
Browse files Browse the repository at this point in the history
最低限の SEO の設定
  • Loading branch information
hayato-osh authored Apr 15, 2024
2 parents 432d56c + 355decc commit 26863e7
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 10 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@astrojs/check": "^0.5.10",
"@astrojs/tailwind": "^5.1.0",
"astro": "^4.6.1",
"astro-seo": "^0.8.3",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
},
Expand Down
14 changes: 9 additions & 5 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---
import { config } from "@/config";
import ThemeIcon from "./ThemeIcon.astro";
---
<header class="h-8 flex items-center justify-between">
<nav>
<a href="/tags">tags</a>
</nav>
<ThemeIcon />
<header class="h-12 flex items-center justify-between">
<a href="/" class="font-bold">{config.website}</a>
<div class="grid grid-cols-[1fr_max-content] items-center gap-2 sm:gap-4">
<nav>
<a href="/tags" class="underline">tags</a>
</nav>
<ThemeIcon />
</div>
</header>
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const author = "fastman";
export const config = {
title: `${author} のブログ`,
description: `${author} のブログです`,
website: "blog.fastman.dev",
};
16 changes: 15 additions & 1 deletion src/layouts/GlobalLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
import { ViewTransitions } from "astro:transitions";
import Footer from "@/components/Footer.astro";
import Header from "@/components/Header.astro";
import { config } from "@/config";
import { SEO } from "astro-seo";
interface Props {
title: string;
desc?: string | undefined;
}
const { title, desc } = Astro.props;
---
<html lang="ja" class="h-full">
<head>
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<meta charset="UTF-8" />

<SEO
charset="utf-8"
title={title}
description={desc ?? config.description}
/>

<ViewTransitions />

Expand Down
3 changes: 2 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
import GlobalLayout from "@/layouts/GlobalLayout.astro";
import { generateTitle } from "@/utils/generateTitle";
import { getPosts } from "@/utils/getPosts";
const posts = await getPosts();
---

<GlobalLayout>
<GlobalLayout title={generateTitle('ホーム')}>
<main>
<ul>
{posts.map(post => (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Props = InferGetStaticPropsType<typeof getStaticPaths>;
const { entry } = Astro.props;
const { Content } = await entry.render();
---
<GlobalLayout>
<GlobalLayout title={entry.data.title} desc={entry.data.description}>
<Post post={entry}>
<Content />
</Post>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/tags/[...tag].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import GlobalLayout from "@/layouts/GlobalLayout.astro";
import { generateTitle } from "@/utils/generateTitle";
import { getTags } from "@/utils/getTags";
import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
Expand All @@ -16,7 +17,7 @@ type Props = InferGetStaticPropsType<typeof getStaticPaths>;
const { tag } = Astro.params;
const { posts } = Astro.props;
---
<GlobalLayout>
<GlobalLayout title={generateTitle(tag, 'タグ一覧')}>
<p>{tag} 一覧</p>
<ul class="grid gap-2">
{posts.map((post) => (
Expand Down
3 changes: 2 additions & 1 deletion src/pages/tags/index.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
import GlobalLayout from "@/layouts/GlobalLayout.astro";
import { generateTitle } from "@/utils/generateTitle";
import { getTags } from "@/utils/getTags";
const tags = await getTags();
---
<GlobalLayout>
<GlobalLayout title={generateTitle('タグ一覧')}>
<ul class="grid gap-2">
{Array.from(tags).map(([key, value]) => (
<li class="grid gap-1">
Expand Down
4 changes: 4 additions & 0 deletions src/utils/generateTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config } from "@/config";

export const generateTitle = (leftTitle: string, rightTitle = config.title) =>
`${leftTitle} | ${rightTitle}`;

0 comments on commit 26863e7

Please sign in to comment.