Fix issues: some document cannot be map from slug
This commit is contained in:
parent
fdf0e419bb
commit
1a11bdb2b0
44
lib/utils.js
44
lib/utils.js
@ -34,7 +34,7 @@ export function getSinglePost(slug) {
|
|||||||
|
|
||||||
|
|
||||||
// List of filenames that will provide existing links to wikilink
|
// List of filenames that will provide existing links to wikilink
|
||||||
let currentFilePath = slug !== "index" ? toFilePath(slug) : Node.getMarkdownFolder() + "/index.md"
|
let currentFilePath = toFilePath(slug)
|
||||||
//console.log("currentFilePath: ", currentFilePath)
|
//console.log("currentFilePath: ", currentFilePath)
|
||||||
|
|
||||||
var fileContent = Node.readFileSync(currentFilePath)
|
var fileContent = Node.readFileSync(currentFilePath)
|
||||||
@ -52,25 +52,35 @@ export function getSinglePost(slug) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cachedSlugMap = getSlugHashMap()
|
||||||
|
|
||||||
export function toFilePath(slug) {
|
export function toFilePath(slug) {
|
||||||
// Construct file name from slug of /notes/abcxyz
|
return cachedSlugMap[slug]
|
||||||
let filePath;
|
}
|
||||||
|
|
||||||
if (slug === '/') {
|
export function getSlugHashMap() {
|
||||||
filePath = Node.getMarkdownFolder() + "/index.md"
|
// This is to solve problem of converting between slug and filepath,
|
||||||
} else {
|
// where previously if I convert a slug to a file path sometime
|
||||||
filePath = Node.getMarkdownFolder() + slug
|
// it does not always resolve to correct filepath, converting function is not bi-directional
|
||||||
.replaceAll('__', '/')
|
// and not conflict-free, other solution was considered (hash file name into a hash, but this
|
||||||
.replaceAll('++++', ' ')
|
// is not SEO-friendly and make url look ugly ==> I chose this
|
||||||
.replaceAll('ambersand', '&')
|
|
||||||
+ ".md";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Node.isFile(filePath)) {
|
const slugMap = new Map()
|
||||||
return filePath
|
getAllMarkdownFiles().map(aFile => {
|
||||||
} else {
|
const aSlug = toSlug(aFile);
|
||||||
return null
|
// if (slugMap.has(aSlug)) {
|
||||||
}
|
// slugMap[aSlug].push(aFile)
|
||||||
|
// } else {
|
||||||
|
// slugMap[aSlug] = [aFile]
|
||||||
|
// }
|
||||||
|
// Note: [Future improvement] Resolve conflict
|
||||||
|
slugMap[aSlug] = aFile
|
||||||
|
})
|
||||||
|
|
||||||
|
slugMap['index'] = Node.getMarkdownFolder() + "/index.md"
|
||||||
|
slugMap['/'] = Node.getMarkdownFolder() + "/index.md"
|
||||||
|
|
||||||
|
return slugMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user