Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ニュースページの追加 #196

Merged
merged 8 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import type { GatsbyNode } from "gatsby"
import { characterKeys, characterInfos } from "./src/constants"
import path from "path"

export const sourceNodes: GatsbyNode["sourceNodes"] = async ({
actions,
Expand All @@ -30,3 +31,53 @@ export const sourceNodes: GatsbyNode["sourceNodes"] = async ({
actions.createNode(node)
})
}

export const createPages: GatsbyNode["createPages"] = async ({
actions,
graphql
}) => {
const { createPage } = actions

// ニュースページ
const newsPostTemplate = path.resolve("src/templates/newsPost.tsx")
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

const result = await graphql(`
query NewsPages {
allMarkdownRemark(filter: { fileAbsolutePath: { regex: "/news/" } }) {
edges {
node {
frontmatter {
slug
}
}
}
}
}
`)

if (result.errors) {
throw result.errors
}

const data = result.data as {
allMarkdownRemark: {
edges: {
node: {
frontmatter: {
slug: string
}
}
}[]
}
}

data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: `/news/${node.frontmatter.slug}/`,
component: newsPostTemplate,
context: {
slug: node.frontmatter.slug,
},
})
})
}
4 changes: 4 additions & 0 deletions src/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const Page: React.FC<{
<Link to={"/update_history/"} className="navbar-item">
変更履歴
</Link>
{/* TODO: リリース時にコメントアウトを外す
<Link to={"/news/"} className="navbar-item">
ニュース
</Link> */}
<a
href="https://hiho.fanbox.cc/"
target={"_blank"}
Expand Down
15 changes: 15 additions & 0 deletions src/markdowns/news/fuga.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
slug: "fuga"
title: "VOICEVOXサンプルニュース_2"
date: "2024-07-01"
---

この文章は `VOICEVOXサンプルニュース_2` のテストです。

## 小見出し

あいうえお

### 小見出し

かきくけこ
15 changes: 15 additions & 0 deletions src/markdowns/news/hoge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
slug: "hoge"
title: "VOICEVOXサンプルニュース_1"
date: "2024-05-01"
---

この文章は `VOICEVOXサンプルニュース_1` のテストです。

## 小見出し

あいうえお

### 小見出し

かきくけこ
9 changes: 9 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ const Main = React.memo(
変更履歴
</Link>
</li>
{/* TODO: リリース時にコメントアウトを外す
<li>
<Link
to={"/news/"}
className="has-text-weight-bold is-underlined"
>
ニュース
</Link>
</li> */}
<li>
<a
href="https://hiho.fanbox.cc/"
Expand Down
54 changes: 54 additions & 0 deletions src/pages/news/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react"
import "../../components/layout.scss"
import { Page } from "../../components/page"
import Seo from "../../components/seo"
import { Link, graphql, useStaticQuery } from "gatsby"
import shareThumb from "../../images/nemo/share-thumbnail.png"

const NewsIndex = () => {
const data = useStaticQuery<Queries.IndexPageQuery>(graphql`
query IndexPage {
allMarkdownRemark (
filter: {fileAbsolutePath: {regex: "/news/"}}
sort: {frontmatter: {date: DESC}}
) {
edges {
node {
html
frontmatter {
title
slug
date(formatString: "YYYY/MM/DD")
}
}
}
}
}
`);

return (
<Page>
<Seo
title="ニュース | VOICEVOX"
description="無料で使える中品質なテキスト読み上げ・歌声合成ソフトウェア。商用・非商用問わず無料で、誰でも簡単にお使いいただけます。イントネーションを詳細に調整することも可能です。"
image={shareThumb}
noindex={true} // TODO: リリース時に外す
/>
<section className="section">
<div className="container is-max-desktop">
<h1 className="title">ニュース</h1>
{data.allMarkdownRemark.edges.map((edge) => (
<div key={edge.node.frontmatter!.slug} className="mb-3">
<Link to={`/news/${edge.node.frontmatter!.slug}`}>
{edge.node.frontmatter!.title}
</Link>
<p className="has-text-grey-light">{edge.node.frontmatter!.date}</p>
</div>
))}
</div>
</section>
</Page>
)
}

export default NewsIndex
45 changes: 45 additions & 0 deletions src/templates/newsPost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react"
import "../components/layout.scss"
import { Page } from "../components/page"
import Seo from "../components/seo"
import { graphql } from "gatsby"

const NewsPost = ({ data }) => {
const { markdownRemark } = data;
const { frontmatter, html } = markdownRemark;

return (
<Page>
<Seo
title={`${frontmatter.title} | ニュース | VOICEVOX`}
description="無料で使える中品質なテキスト読み上げ・歌声合成ソフトウェア。商用・非商用問わず無料で、誰でも簡単にお使いいただけます。イントネーションを詳細に調整することも可能です。"
noindex={true} // TODO: リリース時に外す
/>
<section className="section">
<div className="container is-max-desktop">
<h1 className="title">{frontmatter.title}</h1>
<p className="has-text-grey-light">{frontmatter.date}</p>
<div
className="markdown mt-5"
dangerouslySetInnerHTML={{ __html: html }}
/>
</div>
</section>
</Page>
)
}

export const query = graphql`
query($slug: String!) {
markdownRemark(frontmatter: { slug: { eq: $slug } }) {
html
frontmatter {
slug
title
date(formatString: "YYYY/MM/DD")
}
}
}
`;

export default NewsPost
Loading