@tenjuu99/blog 0.2.55 → 0.2.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,6 +11,11 @@ let categoryTreeCache = null
|
|
|
11
11
|
export function buildCategoryTree(data = allData, conf = config) {
|
|
12
12
|
const tree = {}
|
|
13
13
|
const urlCase = conf.category?.url_case || 'lower'
|
|
14
|
+
const urlSeparator = conf.category?.url_separator || '-'
|
|
15
|
+
const rawUrlPrefix = conf.category?.url_prefix || ''
|
|
16
|
+
const urlPrefix = rawUrlPrefix
|
|
17
|
+
? '/' + rawUrlPrefix.replace(/^\/+|\/+$/g, '')
|
|
18
|
+
: ''
|
|
14
19
|
const maxDepth = conf.category?.max_depth || 3
|
|
15
20
|
|
|
16
21
|
for (const [name, page] of Object.entries(data)) {
|
|
@@ -19,11 +24,12 @@ export function buildCategoryTree(data = allData, conf = config) {
|
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
const categoryPath = page.category.slice(0, maxDepth)
|
|
22
|
-
let currentPath =
|
|
27
|
+
let currentPath = urlPrefix
|
|
23
28
|
|
|
24
29
|
for (let i = 0; i < categoryPath.length; i++) {
|
|
25
30
|
const category = categoryPath[i]
|
|
26
|
-
|
|
31
|
+
let categoryUrl = urlCase === 'lower' ? category.toLowerCase() : category
|
|
32
|
+
categoryUrl = categoryUrl.replace(/\s+/g, urlSeparator)
|
|
27
33
|
currentPath += `/${categoryUrl}`
|
|
28
34
|
|
|
29
35
|
if (!tree[currentPath]) {
|