Skip to content

Commit 365501b

Browse files
committed
feat: Point category/version pages to their correct url
Related to #19
1 parent 7607aeb commit 365501b

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

extensions/edit-url/extension.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
11
'use strict'
22

3-
const CATEGORIES = "categories/pages"
4-
const VERSIONS = "versions/pages"
5-
const INDEX = "index.adoc"
3+
const PARTIALS = "partials"
4+
const CATEGORIES = "categories/pages"
5+
const VERSIONS = "versions/pages"
6+
const INDEX = "index.adoc"
7+
const RE_CATEGORY1 = /modules\/categories\/pages\/(?<category>\w+)\/index.adoc/
8+
const RE_VERSION1 = /modules\/versions\/pages\/(?<version>.+?)\/index.adoc/
9+
const RE_CATEGORY2 = /modules\/categories\/pages\/\w+\/(?<version>.+?)\/index.adoc/
10+
const RE_VERSION2 = /modules\/versions\/pages\/.+?\/(?<category>\w+)\/index.adoc/
611

712
module.exports.register = function () {
8-
this
9-
.on('contentAggregated', ({ contentAggregate }) => {
10-
contentAggregate.forEach(({ name, title, version, nav, files }) => {
11-
files.forEach((file) => {
12-
if (file.src.basename == INDEX) return
13-
if (file.src.path.substring(CATEGORIES) ||
14-
file.src.path.substring(VERSIONS)) {
15-
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
16-
file.src.origin.refname + "/features/" +
17-
file.src.basename
18-
}
19-
})
20-
})
13+
this.on('contentAggregated', ({ contentAggregate }) => {
14+
contentAggregate.forEach(({ name, title, version, nav, files }) => {
15+
files.forEach((file) => {
16+
let path = file.src.path
17+
18+
if (path.includes(PARTIALS)) {
19+
// skip
20+
} else if (file.src.basename == INDEX) {
21+
let match_c1 = path.match(RE_CATEGORY1)
22+
let match_c2 = path.match(RE_CATEGORY2)
23+
let match_v1 = path.match(RE_VERSION1)
24+
let match_v2 = path.match(RE_VERSION2)
25+
26+
if (match_c1) {
27+
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
28+
file.src.origin.refname + "/features/_categories/" +
29+
match_c1.groups.category + ".adoc"
30+
} else if(match_c2) {
31+
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
32+
file.src.origin.refname + "/features/_versions/" +
33+
match_c2.groups.version + ".adoc"
34+
} else if(match_v2) {
35+
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
36+
file.src.origin.refname + "/features/_categories/" +
37+
match_v2.groups.category + ".adoc"
38+
} else if (match_v1) {
39+
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
40+
file.src.origin.refname + "/features/_versions/" +
41+
match_v1.groups.version + ".adoc"
42+
}
43+
} else if (path.includes(CATEGORIES) ||
44+
path.includes(VERSIONS)) {
45+
file.src.editUrl = file.src.origin.webUrl + "/blob/" +
46+
file.src.origin.refname + "/features/" +
47+
file.src.basename
48+
}
49+
})
2150
})
51+
})
2252
}

0 commit comments

Comments
 (0)