File tree Expand file tree Collapse file tree 4 files changed +41
-3
lines changed Expand file tree Collapse file tree 4 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 84
84
"prismjs" : " ^1.9.0" ,
85
85
"raw-loader" : " ^0.5.1" ,
86
86
"redirect-webpack-plugin" : " ^0.1.1" ,
87
+ "remark" : " ^9.0.0" ,
87
88
"remark-autolink-headings" : " ^5.0.0" ,
88
89
"remark-loader" : " ^0.3.0" ,
89
90
"remark-mermaid" : " ^0.2.0" ,
116
117
"react-hot-loader" : " ^4.0.0-beta.12" ,
117
118
"react-router" : " ^4.2.0" ,
118
119
"react-router-dom" : " ^4.2.2" ,
120
+ "remark-parse" : " ^5.0.0" ,
121
+ "remark-slug" : " ^5.0.0" ,
119
122
"tool-list" : " ^0.11.0" ,
123
+ "unified" : " ^6.1.6" ,
124
+ "unist-util-visit" : " ^1.3.0" ,
120
125
"webpack.vote" : " ^0.1.2" ,
121
126
"whatwg-fetch" : " ^2.0.3"
122
127
}
Original file line number Diff line number Diff line change
1
+ var remark = require ( 'remark' ) ;
2
+ var slug = require ( 'remark-slug' ) ;
3
+ var visit = require ( 'unist-util-visit' ) ;
4
+
5
+ module . exports = function getAnchors ( content ) {
6
+ let anchors = [ ] ;
7
+
8
+ remark ( )
9
+ . use ( slug )
10
+ . use ( pl )
11
+ . process ( content , ( err , file ) => {
12
+ if ( err ) {
13
+ throw err ;
14
+ }
15
+ } ) ;
16
+
17
+ function pl ( ) {
18
+ return function transformer ( ast ) {
19
+ visit ( ast , 'heading' , visitor ) ;
20
+ } ;
21
+
22
+ function visitor ( node ) {
23
+ anchors . push ( {
24
+ title : node . children [ 0 ] . value ,
25
+ id : node . data . id
26
+ } ) ;
27
+ }
28
+ }
29
+
30
+ return anchors ;
31
+ } ;
Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' ) ;
2
2
const FrontMatter = require ( 'front-matter' ) ;
3
+ const RemarkAnchors = require ( './remark-anchors' ) ;
3
4
4
5
module . exports = function ( item , options ) {
5
6
item . url = item . path
@@ -19,6 +20,6 @@ module.exports = function(item, options) {
19
20
let { attributes } = FrontMatter ( content ) ;
20
21
21
22
Object . assign ( item , attributes ) ;
22
- item . anchors = [ ] ; // TODO: Add actual anchors
23
+ item . anchors = RemarkAnchors ( content ) ;
23
24
}
24
25
}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const CleanPlugin = require('clean-webpack-plugin');
5
5
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
6
6
const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
7
7
const DirectoryTreePlugin = require ( 'directory-tree-webpack-plugin' ) ;
8
- const treePluginEnhacer = require ( './src/utilities/treePluginEnhacer .js' ) ;
8
+ const TreeEnhancer = require ( './src/utilities/tree-plugin-enhancer .js' ) ;
9
9
10
10
module . exports = ( env = { } ) => ( {
11
11
devtool : 'source-map' ,
@@ -35,6 +35,7 @@ module.exports = (env = {}) => ({
35
35
options : {
36
36
plugins : [
37
37
// TODO: Add necessary remark plugins
38
+ require ( 'remark-slug' ) ,
38
39
require ( 'remark-autolink-headings' ) ,
39
40
require ( 'remark-mermaid' )
40
41
]
@@ -109,7 +110,7 @@ module.exports = (env = {}) => ({
109
110
dir : 'src/content' ,
110
111
path : 'src/_content.json' ,
111
112
extensions : / \. m d / ,
112
- enhance : treePluginEnhacer ,
113
+ enhance : TreeEnhancer ,
113
114
filter : item => item . name !== 'images' ,
114
115
sort : ( a , b ) => {
115
116
let group1 = ( a . group || '' ) . toLowerCase ( ) ;
You can’t perform that action at this time.
0 commit comments