wip(org): More changes for #5230
Also clears some of the old stuff for showcase/blog posts
This commit is contained in:
parent
e2c774b297
commit
9f1fe751e8
9 changed files with 31 additions and 95 deletions
|
@ -1,62 +0,0 @@
|
|||
import { localePath } from 'shared/utils.mjs'
|
||||
import { siteConfig as config } from 'site/site.config.mjs'
|
||||
|
||||
/**
|
||||
* get pre-generated paths for each language for post slug pages
|
||||
* @param {Object} posts an object holding all the posts
|
||||
* @return {String[]} paths for the most recent posts in all locales
|
||||
*/
|
||||
export const getPostSlugPaths = (posts) => {
|
||||
const paths = []
|
||||
|
||||
for (const lang in posts) {
|
||||
paths.push(
|
||||
...Object.keys(posts[lang])
|
||||
.slice(0, config.posts.preGenerate)
|
||||
.map((slug) => localePath(lang, slug))
|
||||
)
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
/**
|
||||
* get pre-generated paths for each language for post index pages
|
||||
* @param {Object} posts an object keyed by locale of posts sorted by date published
|
||||
* @param {String} type post type: blog, showcase, or newsletter
|
||||
* @return {String[]} paths for the first two pages of posts in all locales
|
||||
*/
|
||||
export const getPostIndexPaths = (posts, type) => {
|
||||
const paths = []
|
||||
for (const language in posts) {
|
||||
paths.push(localePath(language, `${type}/page/1`))
|
||||
paths.push(localePath(language, `${type}/page/2`))
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
/**
|
||||
* get static props for a post index page
|
||||
* @param {Object} pagenr the current page number in the pagination
|
||||
* @param {Object} posts on object keyed by slug holding the posts title
|
||||
* @return {Object} meta on object keyed by slug holding the posts metadata
|
||||
* @return {Object[]} props.posts the posts to link to on the page
|
||||
* @return {Number} props.current the current page number
|
||||
* @return {Number} props.total the total number of pages
|
||||
*/
|
||||
export const getPostIndexProps = (pagenr, posts, meta) => {
|
||||
const pageNum = parseInt(pagenr)
|
||||
const numLocPages = Math.ceil(Object.keys(posts).length / config.posts.perPage)
|
||||
if (pageNum > numLocPages) return false
|
||||
|
||||
const pagePosts = Object.entries(posts)
|
||||
.slice(config.posts.perPage * (pageNum - 1), config.posts.perPage * pageNum)
|
||||
.map(([slug, post]) => ({
|
||||
s: slug,
|
||||
...post,
|
||||
...meta[slug],
|
||||
}))
|
||||
|
||||
return { posts: pagePosts, current: pageNum, total: numLocPages }
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
// Dependencies
|
||||
import dynamic from 'next/dynamic'
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||
import { nsMerge } from 'shared/utils.mjs'
|
||||
import { nsMerge, getSearchParam } from 'shared/utils.mjs'
|
||||
// Hooks
|
||||
import { useTranslation } from 'next-i18next'
|
||||
import { useState, useEffect } from 'react'
|
||||
// Components
|
||||
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
|
||||
import { ns as authNs } from 'shared/components/wrappers/auth/index.mjs'
|
||||
|
@ -32,8 +33,14 @@ const DynamicSet = dynamic(
|
|||
* when path and locale come from static props (as here)
|
||||
* or set them manually.
|
||||
*/
|
||||
const SetPage = ({ page, id }) => {
|
||||
const SetPage = ({ page }) => {
|
||||
const { t } = useTranslation(ns)
|
||||
const [id, setId] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
const newId = getSearchParam('id')
|
||||
if (newId !== id) setId(newId)
|
||||
}, [id])
|
||||
|
||||
return (
|
||||
<PageWrapper {...page} title={`${t('sets')}: #${id}`}>
|
||||
|
@ -46,22 +53,14 @@ const SetPage = ({ page, id }) => {
|
|||
|
||||
export default SetPage
|
||||
|
||||
export async function getStaticProps({ locale, params }) {
|
||||
export async function getStaticProps({ locale }) {
|
||||
return {
|
||||
props: {
|
||||
...(await serverSideTranslations(locale, ns)),
|
||||
id: params.id,
|
||||
page: {
|
||||
locale,
|
||||
path: ['account', 'sets', params.id],
|
||||
path: ['account', 'set'],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* getStaticPaths() is used to specify for which routes (think URLs)
|
||||
* this page should be used to generate the result.
|
||||
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
|
||||
*/
|
||||
export const getStaticPaths = async () => ({ paths: [], fallback: true })
|
|
@ -47,10 +47,11 @@ export async function getStaticProps({ params, locale }) {
|
|||
}
|
||||
|
||||
export const getStaticPaths = async () => {
|
||||
return {
|
||||
paths: getPostSlugPaths(posts),
|
||||
fallback: 'blocking',
|
||||
const paths = []
|
||||
for (const lang in posts) {
|
||||
paths.push(...Object.keys(posts[lang]).map((slug) => localePath(lang, slug)))
|
||||
}
|
||||
return { paths, fallback: false }
|
||||
}
|
||||
|
||||
export default BlogPage
|
||||
|
|
|
@ -54,6 +54,6 @@ export async function getStaticProps({ locale, params }) {
|
|||
export async function getStaticPaths() {
|
||||
return {
|
||||
paths: [...collection].map((design) => `/designs/${design}`),
|
||||
fallback: 'blocking',
|
||||
fallback: false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { nsMerge } from 'shared/utils.mjs'
|
||||
import { nsMerge, localePath } from 'shared/utils.mjs'
|
||||
import { siteConfig } from 'site/site.config.mjs'
|
||||
// Used in static paths
|
||||
import { pages } from 'site/prebuild/docs.en.mjs'
|
||||
// Dependencies
|
||||
|
@ -69,11 +70,11 @@ export async function getStaticProps({ locale, params }) {
|
|||
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
|
||||
*/
|
||||
export async function getStaticPaths() {
|
||||
const somePaths = Object.keys(pages).filter((path) => path !== 'docs')
|
||||
//.filter((path) => path.split('/').length < 5)
|
||||
const allSlugs = Object.keys(pages).filter((path) => path !== 'docs')
|
||||
const paths = []
|
||||
for (const lang of siteConfig.languages) {
|
||||
paths.push(...allSlugs.map((slug) => localePath(lang, slug)))
|
||||
}
|
||||
|
||||
return {
|
||||
paths: somePaths.map((key) => `/${key}`),
|
||||
fallback: false,
|
||||
}
|
||||
return { paths, fallback: false }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { nsMerge } from 'shared/utils.mjs'
|
||||
import { nsMerge, localePath } from 'shared/utils.mjs'
|
||||
import { pages as posts } from 'site/prebuild/showcase.mjs'
|
||||
import { getPostSlugPaths } from 'site/components/mdx/posts/utils.mjs'
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||
|
@ -52,10 +52,11 @@ export async function getStaticProps({ params, locale }) {
|
|||
}
|
||||
|
||||
export const getStaticPaths = async () => {
|
||||
return {
|
||||
paths: getPostSlugPaths(posts),
|
||||
fallback: 'blocking',
|
||||
const paths = []
|
||||
for (const lang in posts) {
|
||||
paths.push(...Object.keys(posts[lang]).map((slug) => localePath(lang, slug)))
|
||||
}
|
||||
return { paths, fallback: false }
|
||||
}
|
||||
|
||||
export default ShowcasePage
|
||||
|
|
|
@ -20,8 +20,4 @@ export const siteConfig = {
|
|||
languagesWip: [],
|
||||
site: 'FreeSewing.org',
|
||||
tld: 'org',
|
||||
posts: {
|
||||
preGenerate: 6,
|
||||
perPage: 50,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -427,7 +427,7 @@ export const Mset = ({ id, publicOnly = false }) => {
|
|||
</DisplayRow>
|
||||
{mset.public && (
|
||||
<DisplayRow title={t('permalink')}>
|
||||
<PageLink href={`/sets/${mset.id}`} txt={`/sets/${mset.id}`} />
|
||||
<PageLink href={`/set?id=${mset.id}`} txt={`/set?id=${mset.id}`} />
|
||||
</DisplayRow>
|
||||
)}
|
||||
</>
|
||||
|
@ -746,7 +746,7 @@ export const Sets = () => {
|
|||
/>
|
||||
</label>
|
||||
<div className="w-full">
|
||||
<MsetCard control={control} href={`/account/sets/${set.id}`} set={set} size="md" />
|
||||
<MsetCard control={control} href={`/account/set?id=${set.id}`} set={set} size="md" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue