git ssb

2+

cel / scuttlebot.io



Commit 3fac22a4a27f3a65427e7f145c9f55db93a0b795

Link markdown links to ssb refs

cel committed on 4/7/2017, 11:17:29 PM
Parent: c12cf209d49b72ac4627e8082069e5baf259a9aa

Files changed

markdown.jschanged
package.jsonchanged
markdown.jsView
@@ -3,8 +3,10 @@
33 var html = require('remark-html')
44 var slug = require('remark-slug')
55 var autolinkHeadings = require('remark-autolink-headings')
66 var com = require('./tmpl/com.part')
7 +var select = require('unist-util-select')
8 +var ssbRef = require('ssb-ref')
79
810 const linkSvg = '<svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg>'
911
1012 module.exports.doc = function (path) {
@@ -17,8 +19,9 @@
1719 })
1820 .use(html)
1921 .use(injectTOC)
2022 .use(transformCodeExamples)
23 + .use(transformSsbLinks)
2124 .process(text)
2225 }
2326
2427 // find all h2s and create a dropdown table-of-contents
@@ -98,4 +101,16 @@
98101 })
99102
100103 return com.code(codes)
101104 }
105 +
106 +// add a prefix to links to ssb refs
107 +function transformSsbLinks (remark, options) {
108 + return ast => {
109 + select(ast, "link").forEach(link => {
110 + if (ssbRef.isLink(link.url)) {
111 + link.url = 'https://git.scuttlebot.io/' + link.url
112 + }
113 + })
114 + return ast
115 + }
116 +}
package.jsonView
@@ -17,7 +17,9 @@
1717 "dependencies": {
1818 "remark": "^4.1.2",
1919 "remark-autolink-headings": "^3.0.0",
2020 "remark-html": "^3.0.0",
21- "remark-slug": "^4.1.0"
21 + "remark-slug": "^4.1.0",
22 + "ssb-ref": "^2.6.3",
23 + "unist-util-select": "^1.5.0"
2224 }
2325 }

Built with git-ssb-web