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 8484 "prismjs" : " ^1.9.0" ,
8585 "raw-loader" : " ^0.5.1" ,
8686 "redirect-webpack-plugin" : " ^0.1.1" ,
87+ "remark" : " ^9.0.0" ,
8788 "remark-autolink-headings" : " ^5.0.0" ,
8889 "remark-loader" : " ^0.3.0" ,
8990 "remark-mermaid" : " ^0.2.0" ,
117118 "react-hot-loader" : " ^4.0.0-beta.12" ,
118119 "react-router" : " ^4.2.0" ,
119120 "react-router-dom" : " ^4.2.2" ,
121+ "remark-parse" : " ^5.0.0" ,
122+ "remark-slug" : " ^5.0.0" ,
120123 "tool-list" : " ^0.11.0" ,
124+ "unified" : " ^6.1.6" ,
125+ "unist-util-visit" : " ^1.3.0" ,
121126 "webpack.vote" : " ^0.1.2" ,
122127 "whatwg-fetch" : " ^2.0.3"
123128 }
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 11const fs = require ( 'fs' ) ;
22const FrontMatter = require ( 'front-matter' ) ;
3+ const RemarkAnchors = require ( './remark-anchors' ) ;
34
45module . exports = function ( item , options ) {
56 item . url = item . path
@@ -19,6 +20,6 @@ module.exports = function(item, options) {
1920 let { attributes } = FrontMatter ( content ) ;
2021
2122 Object . assign ( item , attributes ) ;
22- item . anchors = [ ] ; // TODO: Add actual anchors
23+ item . anchors = RemarkAnchors ( content ) ;
2324 }
2425}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const CleanPlugin = require('clean-webpack-plugin');
55const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
66const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
77const DirectoryTreePlugin = require ( 'directory-tree-webpack-plugin' ) ;
8- const treePluginEnhacer = require ( './src/utilities/treePluginEnhacer .js' ) ;
8+ const TreeEnhancer = require ( './src/utilities/tree-plugin-enhancer .js' ) ;
99
1010module . exports = ( env = { } ) => ( {
1111 devtool : 'source-map' ,
@@ -35,6 +35,7 @@ module.exports = (env = {}) => ({
3535 options : {
3636 plugins : [
3737 // TODO: Add necessary remark plugins
38+ require ( 'remark-slug' ) ,
3839 require ( 'remark-autolink-headings' ) ,
3940 require ( 'remark-mermaid' )
4041 ]
@@ -109,7 +110,7 @@ module.exports = (env = {}) => ({
109110 dir : 'src/content' ,
110111 path : 'src/_content.json' ,
111112 extensions : / \. m d / ,
112- enhance : treePluginEnhacer ,
113+ enhance : TreeEnhancer ,
113114 filter : item => item . name !== 'images' ,
114115 sort : ( a , b ) => {
115116 let group1 = ( a . group || '' ) . toLowerCase ( ) ;
You can’t perform that action at this time.
0 commit comments