Skip to content

Commit

Permalink
TOC updated, local fontawesome, anchors are working
Browse files Browse the repository at this point in the history
  • Loading branch information
Rackover committed Feb 10, 2020
1 parent 84ed36b commit 9615859
Show file tree
Hide file tree
Showing 24 changed files with 13,631 additions and 80 deletions.
22 changes: 16 additions & 6 deletions app/layout/default.pug
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
mixin recursive_loop(array, index, current, prefix)
each content, element in array
a(class=(element === current ? "selected" : ""),href=prefix+content.url)
.element(style="text-indent:"+index*15+"px;") #{(index>0 ? "":"") + content.name}
if content.children
+recursive_loop(content.children, index+1, current, prefix)
mixin recursive_loop(array, depth, current, prefix)
- var i = 0
each content, element in array
a(class=(element === current ? "selected" : ""),href=prefix+content.url)
.element(style="text-indent:"+depth*15+"px;")
if (i === Object.keys(array).length-1)
| └
else if (depth===0 && i===0)
| ┌
else
| ├
| #{element===current ? "⦿" : ""} #{content.name}
if content.children
+recursive_loop(content.children, depth+1, current, prefix)
- i++


doctype html
html
head
title #{website.name}
link(rel="stylesheet", href="/res/css/font-awesome-all.css")
block head
link(rel="stylesheet", href=website.links.css)
link(rel="icon", type="image/png", href=website.links.favicon)
Expand Down
78 changes: 12 additions & 66 deletions app/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ const cheerio = require('cheerio')

const mdContainer = require('markdown-it-container')
const mdAnchor = require('markdown-it-anchor')

/*
const mdEmoji = require('markdown-it-emoji')
const mdTaskLists = require('markdown-it-task-lists')
const mdAbbr = require('markdown-it-abbr')
const mdFootnote = require('markdown-it-footnote')
const mdExternalLinks = require('markdown-it-external-links')
const mdAttrs = require('markdown-it-attrs')
const mdExpandTabs = require('markdown-it-expand-tabs')
*/
const mdTable = require('markdown-it-multimd-table')

const _ = require('lodash')
const mdRemove = require('remove-markdown')
Expand Down Expand Up @@ -48,9 +39,14 @@ var mkdown = md({
.use(mdAnchor, {
slugify: _.kebabCase,
permalink: true,
permalinkClass: 'toc-anchor icon-link2',
permalinkClass: 'fa fa-link anchor',
permalinkSymbol: ''
})
.use(mdTable, {
multiline: true,
rowspan: true,
headerless: true,
})

for (let k in containers){
const container = containers[k];
Expand All @@ -65,28 +61,6 @@ for (let k in containers){
});
}

/*
.use(mdEmoji)
.use(mdTaskLists)
.use(mdAbbr)
.use(mdFootnote)
.use(mdExternalLinks, {
externalClassName: 'external-link',
internalClassName: 'internal-link'
})
.use(mdExpandTabs, {
tabWidth: 4
})
.use(mdAttrs);
*/

// Rendering rules
/*
mkdown.renderer.rules.emoji = function (token, idx) {
return '<i class="twa twa-' + _.replace(token[idx].markup, /_/g, '-') + '"></i>'
}
*/

// Video rules

const videoRules = [
Expand Down Expand Up @@ -140,11 +114,9 @@ const parseTree = (content) => {
if (heading.children && heading.children.length > 0 && heading.children[0].type === 'link_open') {
content = mdRemove(heading.children[1].content)
anchor = _.kebabCase(content)
anchor = content
} else {
content = mdRemove(heading.content)
anchor = _.kebabCase(heading.children.reduce((acc, t) => acc + t.content, ''))
anchor = heading.children.reduce((acc, t) => acc + t.content, '')
}

tocArray.push({
Expand Down Expand Up @@ -210,7 +182,7 @@ const parseContent = (content) => {
return ''
}

// Replace internal links to add a /read before them
// Replace internal links to add a /read before them
cr("a").each(function(i, ele) {
const fragments = ele.attribs.href.split("#");
const ref = fragments[0];
Expand All @@ -220,7 +192,7 @@ const parseContent = (content) => {
});

// -> Check for empty first element

/*
let firstElm = cr.root().children().first()[0]
if (firstElm.type === 'tag' && firstElm.name === 'p') {
let firstElmChildren = firstElm.children
Expand All @@ -231,13 +203,6 @@ const parseContent = (content) => {
}
}
// -> Remove links in headers

cr('h1 > a:not(.toc-anchor), h2 > a:not(.toc-anchor), h3 > a:not(.toc-anchor)').each((i, elm) => {
let txtLink = cr(elm).text()
cr(elm).replaceWith(txtLink)
})

// -> Re-attach blockquote styling classes to their parents
cr('blockquote').each((i, elm) => {
Expand All @@ -251,28 +216,9 @@ const parseContent = (content) => {
}
})
// -> Enclose content below headers

cr('h2').each((i, elm) => {
let subH2Content = cr(elm).nextUntil('h1, h2')
cr(elm).after('<div class="indent-h2"></div>')
let subH2Container = cr(elm).next('.indent-h2')
_.forEach(subH2Content, (ch) => {
cr(subH2Container).append(ch)
})
})

cr('h3').each((i, elm) => {
let subH3Content = cr(elm).nextUntil('h1, h2, h3')
cr(elm).after('<div class="indent-h3"></div>')
let subH3Container = cr(elm).next('.indent-h3')
_.forEach(subH3Content, (ch) => {
cr(subH3Container).append(ch)
})
})
// Replace video links with embeds

*/
_.forEach(videoRules, (vrule) => {
cr(vrule.selector).each((i, elm) => {
let originLink = cr(elm).attr('href')
Expand All @@ -291,12 +237,12 @@ const parseContent = (content) => {
})

// Apply align-center to parent

/*
cr('img.align-center').each((i, elm) => {
cr(elm).parent().addClass('align-center')
cr(elm).removeClass('align-center')
})

*/
return Promise.resolve(cr.html())
}

Expand Down
2 changes: 1 addition & 1 deletion app/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {

const whitelist = [
"2a01:cb0c:882:1400:30e6:9ecb:e3c:7aeb", // 970 HOME VAL
"2a01:cb0c:882:1400:ccb7:504:79dc:cc0", // TWONK HOME VAL
"2a01:cb0c:882:1400:158c:7f36:eaa4:b62a", // TWONK HOME VAL
]

function canWrite(req){
Expand Down
4 changes: 3 additions & 1 deletion app/views/read.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ extends ../layout/default.pug
mixin create_toc(tree, depth=0)
each anchor, index in tree
div
span(style="display:inline-block; width:"+depth*15+"px")
span(style="display:inline-block; width:"+depth*10+"px")
if (index === tree.length-1)
| └&gt;
else if (depth===0 && index===0)
| ┌&gt;
else
| ├&gt;
a.link(href="#"+anchor.anchor) #{anchor.content}
Expand Down
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"markdown-it": "^10.0.0",
"markdown-it-anchor": "^5.2.5",
"markdown-it-container": "^2.0.0",
"markdown-it-multimd-table": "^4.0.1",
"pug": "^2.0.4",
"remove-markdown": "^0.3.0",
"winston": "^3.2.1",
Expand Down
Loading

0 comments on commit 9615859

Please sign in to comment.