removed duplicate codes
restructured series database
This commit is contained in:
parent
d4e7a5d7e5
commit
6e8b20a85c
14 changed files with 80 additions and 32 deletions
|
@ -54,7 +54,7 @@ interface Map {
|
||||||
title: string
|
title: string
|
||||||
toc: string // in series home page and ≡ (3 horizontal line) button
|
toc: string // in series home page and ≡ (3 horizontal line) button
|
||||||
length: number
|
length: number
|
||||||
order: string[]
|
order: string[] // url order
|
||||||
tags: string[]
|
tags: string[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,16 @@ const map: Map = {
|
||||||
unsearchable: {},
|
unsearchable: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SeriesMap {
|
||||||
|
// key: url
|
||||||
|
[key: string]: {
|
||||||
|
index: number
|
||||||
|
url: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const seriesMap: SeriesMap = {}
|
||||||
|
|
||||||
// converts file path to url
|
// converts file path to url
|
||||||
function path2URL(pathToConvert: string): string {
|
function path2URL(pathToConvert: string): string {
|
||||||
return `/${path.relative(markdownPath, pathToConvert)}`
|
return `/${path.relative(markdownPath, pathToConvert)}`
|
||||||
|
@ -382,9 +392,37 @@ function recursiveParseSeries(fileOrFolderPath: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileOrFolderName.startsWith("0")) {
|
if (fileOrFolderName.startsWith("0")) {
|
||||||
console.log("new series")
|
|
||||||
} else {
|
|
||||||
map.series[urlPath] = { ...postData, order: [], length: 0 }
|
map.series[urlPath] = { ...postData, order: [], length: 0 }
|
||||||
|
} else {
|
||||||
|
map.posts[urlPath] = postData
|
||||||
|
for (const key of Object.keys(map.series)) {
|
||||||
|
if (urlPath.slice(0, urlPath.lastIndexOf("/")).includes(key)) {
|
||||||
|
const index = parseInt(
|
||||||
|
fileOrFolderName.slice(
|
||||||
|
0,
|
||||||
|
fileOrFolderName.lastIndexOf("_")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isNaN(index)) {
|
||||||
|
throw Error(
|
||||||
|
`Invalid series index at: ${fileOrFolderPath}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemToPush = {
|
||||||
|
index: index,
|
||||||
|
url: urlPath,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seriesMap[key]) {
|
||||||
|
seriesMap[key].push(itemToPush)
|
||||||
|
} else {
|
||||||
|
seriesMap[key] = [itemToPush]
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,5 +476,23 @@ for (const tag in map.tags) {
|
||||||
map.meta.tags.push(tag)
|
map.meta.tags.push(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort series post
|
||||||
|
for (const seriesURL in seriesMap) {
|
||||||
|
seriesMap[seriesURL].sort((a, b) => {
|
||||||
|
if (a.index < b.index) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a.index > b.index) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const seriesURL in seriesMap) {
|
||||||
|
map.series[seriesURL].length = seriesMap[seriesURL].length
|
||||||
|
map.series[seriesURL].order = seriesMap[seriesURL].map((item) => item.url)
|
||||||
|
}
|
||||||
|
|
||||||
// write to src/data/map.json
|
// write to src/data/map.json
|
||||||
fs.writeFileSync(mapFilePath, JSON.stringify(map))
|
fs.writeFileSync(mapFilePath, JSON.stringify(map))
|
||||||
|
|
4
source/markdown/series/my quotes/0.md
Normal file
4
source/markdown/series/my quotes/0.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: my quotes
|
||||||
|
date: 2021-08-01
|
||||||
|
---
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.31
|
title: My Quote NO.10
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.6
|
title: My Quote NO.1
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.7
|
title: My Quote NO.2
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.11
|
title: My Quote NO.3
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.14
|
title: My Quote NO.4
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.16
|
title: My Quote NO.5
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.20
|
title: My Quote NO.6
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.26
|
title: My Quote NO.7
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.28
|
title: My Quote NO.8
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: My Quote NO.30
|
title: My Quote NO.9
|
||||||
date: 2021-03-22
|
date: 2021-03-22
|
||||||
---
|
---
|
||||||
|
|
|
@ -37,9 +37,7 @@ export default class Page extends React.Component<PageProps, PageState> {
|
||||||
let _isUnsearchable = false
|
let _isUnsearchable = false
|
||||||
|
|
||||||
// fetch page
|
// fetch page
|
||||||
let fetchedPage = url.startsWith("/posts")
|
let fetchedPage = posts.posts[url]
|
||||||
? posts.posts[url]
|
|
||||||
: posts.series[url]
|
|
||||||
if (!fetchedPage) {
|
if (!fetchedPage) {
|
||||||
fetchedPage = posts.unsearchable[url]
|
fetchedPage = posts.unsearchable[url]
|
||||||
_isUnsearchable = true
|
_isUnsearchable = true
|
||||||
|
|
|
@ -72,22 +72,12 @@ export default class PostList extends React.Component<
|
||||||
|
|
||||||
postCount++
|
postCount++
|
||||||
const url: string = posts.date[date][length - i - 1]
|
const url: string = posts.date[date][length - i - 1]
|
||||||
if (url.startsWith("/posts")) {
|
PostCards.push(
|
||||||
PostCards.push(
|
<PostCard
|
||||||
<PostCard
|
key={url}
|
||||||
postData={{ url: url, ...posts.posts[url] }}
|
postData={{ url: url, ...posts.posts[url] }}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
PostCards.push(
|
|
||||||
<PostCard
|
|
||||||
postData={{
|
|
||||||
url: url,
|
|
||||||
...posts.series[url],
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue