refactor: improve content json importing
This commit is contained in:
parent
a3c0990804
commit
36b1ecd8ec
10 changed files with 43 additions and 28 deletions
|
@ -3,6 +3,9 @@ const nextConfig = {
|
||||||
output: "export",
|
output: "export",
|
||||||
distDir: "build",
|
distDir: "build",
|
||||||
images: { unoptimized: true },
|
images: { unoptimized: true },
|
||||||
|
experimental: {
|
||||||
|
externalDir: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import contentMap from "@developomp-site/content/exports/contentMap"
|
||||||
import { type ReactNode, useEffect, useState } from "react"
|
import { type ReactNode, useEffect, useState } from "react"
|
||||||
|
|
||||||
import PostCard from "@/components/PostCard"
|
import PostCard from "@/components/PostCard"
|
||||||
import ShowMoreButton from "@/components/ShowMoreButton"
|
import ShowMoreButton from "@/components/ShowMoreButton"
|
||||||
import contentMap from "@/contentMap"
|
|
||||||
|
|
||||||
const totalPosts = Object.keys(contentMap.posts).length
|
const totalPosts = Object.keys(contentMap.posts).length
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
import contentMap from "@developomp-site/content/exports/contentMap"
|
||||||
import type { PageData } from "@developomp-site/content/src/types/types"
|
import type { PageData } from "@developomp-site/content/src/types/types"
|
||||||
|
|
||||||
import contentMap from "@/contentMap"
|
|
||||||
|
|
||||||
import type { Params } from "./page"
|
import type { Params } from "./page"
|
||||||
|
|
||||||
export enum PageType {
|
export enum PageType {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import "./Page.scss"
|
import "./Page.scss"
|
||||||
|
|
||||||
|
import contentMap from "@developomp-site/content/exports/contentMap"
|
||||||
import { type Metadata } from "next"
|
import { type Metadata } from "next"
|
||||||
import { type ParsedUrlQuery } from "querystring"
|
import { type ParsedUrlQuery } from "querystring"
|
||||||
|
|
||||||
|
@ -8,7 +9,6 @@ import Card from "@/components/Card"
|
||||||
import PostCard from "@/components/PostCard"
|
import PostCard from "@/components/PostCard"
|
||||||
import Tag from "@/components/Tag"
|
import Tag from "@/components/Tag"
|
||||||
import TagList from "@/components/TagList"
|
import TagList from "@/components/TagList"
|
||||||
import contentMap from "@/contentMap"
|
|
||||||
|
|
||||||
import { getData, PageType } from "./helper"
|
import { getData, PageType } from "./helper"
|
||||||
import Meta from "./Meta"
|
import Meta from "./Meta"
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
import contentMapJson from "@developomp-site/content/dist/map.json"
|
|
||||||
import { type ContentMap } from "@developomp-site/content/src/types/types"
|
|
||||||
|
|
||||||
export default contentMapJson as ContentMap
|
|
|
@ -1,5 +1,5 @@
|
||||||
import portfolio from "@developomp-site/content/dist/portfolio.json"
|
import type { ProjectKey } from "@developomp-site/content/exports/portfolio"
|
||||||
import type { PortfolioProject } from "@developomp-site/content/src/types/types"
|
import portfolio from "@developomp-site/content/exports/portfolio"
|
||||||
import type { Metadata } from "next"
|
import type { Metadata } from "next"
|
||||||
|
|
||||||
import Badge from "@/components/Badge"
|
import Badge from "@/components/Badge"
|
||||||
|
@ -12,23 +12,15 @@ function getSkills(): JSX.Element[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProjects(): JSX.Element[] {
|
function getProjects(): JSX.Element[] {
|
||||||
const projects = []
|
return (Object.keys(portfolio.projects) as ProjectKey[]).map(
|
||||||
|
(projectID) => (
|
||||||
for (const projectID in portfolio.projects) {
|
|
||||||
projects.push(
|
|
||||||
<ProjectCard
|
<ProjectCard
|
||||||
key={projectID}
|
key={projectID}
|
||||||
projectID={projectID}
|
projectID={projectID}
|
||||||
project={
|
project={portfolio.projects[projectID]}
|
||||||
portfolio.projects[
|
|
||||||
projectID as keyof typeof portfolio.projects
|
|
||||||
] as PortfolioProject
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
return projects
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import "./style.scss"
|
import "./style.scss"
|
||||||
|
|
||||||
import Toc from "@developomp-site/blog/src/app/[category]/[[...slug]]/Toc"
|
import Toc from "@developomp-site/blog/src/app/[category]/[[...slug]]/Toc"
|
||||||
import portfolio from "@developomp-site/content/dist/portfolio.json"
|
import type { ProjectKey } from "@developomp-site/content/exports/portfolio"
|
||||||
|
import portfolio from "@developomp-site/content/exports/portfolio"
|
||||||
import { faGithub } from "@fortawesome/free-brands-svg-icons"
|
import { faGithub } from "@fortawesome/free-brands-svg-icons"
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
||||||
import { type Metadata } from "next"
|
import { type Metadata } from "next"
|
||||||
|
@ -21,14 +22,14 @@ interface Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
id: keyof typeof portfolio.projects
|
id: ProjectKey
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: Params
|
params: Params
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getData(id: keyof typeof portfolio.projects): Promise<Data> {
|
async function getData(id: ProjectKey): Promise<Data> {
|
||||||
const content = await import(
|
const content = await import(
|
||||||
`@developomp-site/content/dist/content/projects/${id}.json`
|
`@developomp-site/content/dist/content/projects/${id}.json`
|
||||||
)
|
)
|
||||||
|
@ -46,9 +47,9 @@ async function getData(id: keyof typeof portfolio.projects): Promise<Data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateStaticParams(): Promise<Params[]> {
|
export async function generateStaticParams(): Promise<Params[]> {
|
||||||
return (
|
return (Object.keys(portfolio.projects) as ProjectKey[]).map((id) => ({
|
||||||
Object.keys(portfolio.projects) as (keyof typeof portfolio.projects)[]
|
id,
|
||||||
).map((id) => ({ id }))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||||
|
|
4
packages/content/exports/contentMap.ts
Normal file
4
packages/content/exports/contentMap.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import contentMap from "../dist/map.json"
|
||||||
|
import { type ContentMap } from "../src/types/types"
|
||||||
|
|
||||||
|
export default contentMap as ContentMap
|
14
packages/content/exports/portfolio.ts
Normal file
14
packages/content/exports/portfolio.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import portfolio from "../dist/portfolio.json" assert { type: "json" }
|
||||||
|
import type { PortfolioProject } from "../src/types/types"
|
||||||
|
|
||||||
|
export type ProjectKey = keyof typeof portfolio.projects
|
||||||
|
|
||||||
|
// sort of like src/types/types.ts > PortfolioData but exported
|
||||||
|
export default portfolio as {
|
||||||
|
// waiting for https://github.com/microsoft/TypeScript/issues/32063
|
||||||
|
skills: string[]
|
||||||
|
|
||||||
|
projects: {
|
||||||
|
[key in ProjectKey]: PortfolioProject
|
||||||
|
}
|
||||||
|
}
|
6
packages/content/exports/tsconfig.json
Normal file
6
packages/content/exports/tsconfig.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue