slug page get all pages
This commit is contained in:
1 parent
deed1b2e8d
commit
b6bc96e47f
1 file changed
+30
-6
+30
-6
@@ -16,6 +16,25 @@ import { Youtube } from '@/components/Youtube'
|
|||||||
import { createPage, createPageUrls } from '@/remote/factory'
|
import { createPage, createPageUrls } from '@/remote/factory'
|
||||||
import { paramsToSlug } from '@/remote/lib'
|
import { paramsToSlug } from '@/remote/lib'
|
||||||
|
|
||||||
|
async function getUrls() {
|
||||||
|
let urls = []
|
||||||
|
|
||||||
|
const limit = 100
|
||||||
|
let start = 0
|
||||||
|
while (true) {
|
||||||
|
const url = `https://hudozka.tmshv.com/pages?_limit=${limit}&_start=${start}`
|
||||||
|
const res = await apiGet(createPageUrls)(url, null)
|
||||||
|
|
||||||
|
if (!res || res.items.length === 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
urls = [...urls, ...res.items]
|
||||||
|
}
|
||||||
|
|
||||||
|
return urls
|
||||||
|
}
|
||||||
|
|
||||||
const File: React.SFC<FileTokenData> = props => {
|
const File: React.SFC<FileTokenData> = props => {
|
||||||
const fileSize = size(props.file_size)
|
const fileSize = size(props.file_size)
|
||||||
const format = ext(props.file_format)
|
const format = ext(props.file_format)
|
||||||
@@ -146,6 +165,8 @@ export const getStaticProps: GetStaticProps<any> = async ctx => {
|
|||||||
const url = `https://hudozka.tmshv.com/pages?slug=${slug}`
|
const url = `https://hudozka.tmshv.com/pages?slug=${slug}`
|
||||||
const page = await apiGet(createPage)(url, null)
|
const page = await apiGet(createPage)(url, null)
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
console.log('kek something happend');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
}
|
}
|
||||||
@@ -161,6 +182,13 @@ export const getStaticProps: GetStaticProps<any> = async ctx => {
|
|||||||
.build()
|
.build()
|
||||||
const tokens = page.tokens
|
const tokens = page.tokens
|
||||||
|
|
||||||
|
tokens.push({
|
||||||
|
token: 'slug',
|
||||||
|
data: {
|
||||||
|
slug,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
tokens,
|
tokens,
|
||||||
@@ -174,15 +202,11 @@ export const getStaticProps: GetStaticProps<any> = async ctx => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getStaticPaths = async () => {
|
export const getStaticPaths = async () => {
|
||||||
let apiUrl = `https://hudozka.tmshv.com/pages`
|
const urls = await getUrls()
|
||||||
const urls = await apiGet(createPageUrls)(apiUrl, null)
|
|
||||||
if (!urls) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fallback: false,
|
fallback: false,
|
||||||
paths: urls.items
|
paths: urls
|
||||||
.map(path => {
|
.map(path => {
|
||||||
const slug = tail(path.split('/'))
|
const slug = tail(path.split('/'))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user