1
1
'use strict'
2
2
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 = / m o d u l e s \/ c a t e g o r i e s \/ p a g e s \/ (?< category > \w + ) \/ i n d e x .a d o c /
8
+ const RE_VERSION1 = / m o d u l e s \/ v e r s i o n s \/ p a g e s \/ (?< version > .+ ?) \/ i n d e x .a d o c /
9
+ const RE_CATEGORY2 = / m o d u l e s \/ c a t e g o r i e s \/ p a g e s \/ \w + \/ (?< version > .+ ?) \/ i n d e x .a d o c /
10
+ const RE_VERSION2 = / m o d u l e s \/ v e r s i o n s \/ p a g e s \/ .+ ?\/ (?< category > \w + ) \/ i n d e x .a d o c /
6
11
7
12
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
+ } )
21
50
} )
51
+ } )
22
52
}
0 commit comments