Skip to content

Commit

Permalink
Fix getStaticData #129
Browse files Browse the repository at this point in the history
  • Loading branch information
qrac committed Oct 28, 2024
1 parent 3a44bb0 commit 486159e
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "3.1.6",
"version": "3.1.7",
"private": true,
"dependencies": {
"preact": "^10.16.0"
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minista-monorepo",
"version": "3.1.6",
"version": "3.1.7",
"private": true,
"engines": {
"node": ">=14.15.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-minista/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-minista",
"description": "Scaffolding for minista projects",
"version": "3.1.6",
"version": "3.1.7",
"type": "module",
"bin": {
"create-minista": "./bin/create-minista.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-minista/templates/minimal-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"semi": false
},
"devDependencies": {
"minista": "^3.1.6",
"minista": "^3.1.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-minista/templates/minimal-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@types/react": "^18.2.16",
"@types/react-dom": "^18.2.7",
"minista": "^3.1.6",
"minista": "^3.1.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/minista/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "minista",
"description": "Static site generator with 100% static export from React and Vite",
"version": "3.1.6",
"version": "3.1.7",
"type": "module",
"engines": {
"node": ">=14.15.0"
Expand Down
10 changes: 4 additions & 6 deletions packages/minista/src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ export function getPages(): Page[] {
const pages: Page[] = Object.keys(PAGES).map((page) => {
const pagePath = page
.replace(/^\/src\/pages\//g, "/")
.replace(/\index|\.tsx$/g, "")
.replace(/\index|\.jsx$/g, "")
.replace(/\index|\.mdx$/g, "")
.replace(/\index|\.md$/g, "")
.replace(/\[\.{3}.+\]/, "*")
.replace(/\[(.+)\]/, ":$1")
.replace(/\index(\.tsx|\.jsx|\.mdx|\.md)$/g, "")
.replace(/\.tsx$|\.jsx$|\.mdx$|\.md$/g, "")
.replace(/\[(\.{3}.+?)\]/g, "*")
.replace(/\[(.+?)\]/g, ":$1")
.replace(/^.\//, "/")
const frontmatter = PAGES[page].frontmatter || {}
const metadata = {
Expand Down
20 changes: 13 additions & 7 deletions playground/core-fetch/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ type PageIssuesProps = PageProps & {
}

export default function (props: PageIssuesProps) {
const langList = ["en", "ja"]
return (
<>
<h1>Issues</h1>
<ul>
{props.issues?.map((item, index) => (
<li key={index}>
<a href={`/issues/${item.number}`}>{item.title}</a>
</li>
))}
</ul>
{langList.map((lang) => (
<div key={lang}>
<h2>lang: {lang}</h2>
<ul>
{props.issues?.map((item, index) => (
<li key={index}>
<a href={`/issues/${lang}/${item.number}`}>{item.title}</a>
</li>
))}
</ul>
</div>
))}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - Function Result Type: Promise<StaticData>
import type { StaticData, PageProps } from "minista"

export async function getStaticData(): Promise<StaticData> {
export async function getStaticData(): Promise<StaticData[]> {
//const apiUrl = "https://api.github.com/repos/qrac/minista/issues"
//const apiParamsQuery = "?state=all&creator=qrac&per_page=5"
//const response = await fetch(apiUrl + apiParamsQuery)
Expand All @@ -12,10 +12,15 @@ export async function getStaticData(): Promise<StaticData> {
const response = await fetch(apiUrl)

const data = await response.json()
return data.map((item: PageIssuesTemplateProps) => ({
props: item,
paths: { number: item.number },
}))
const langList = ["en", "ja"]
return langList
.map((lang) =>
data.map((item: PageIssuesTemplateProps) => ({
props: item,
paths: { lang, number: item.number },
}))
)
.flat()
}

type PageIssuesTemplateProps = PageProps & {
Expand Down

0 comments on commit 486159e

Please sign in to comment.