Add support for inline tags

This commit is contained in:
Ole Eskild Steensen 2023-01-09 18:54:15 +01:00
parent 1bc283c4de
commit 0c46242b0a
5 changed files with 37 additions and 4 deletions

View File

@ -15,6 +15,12 @@ module.exports = function(eleventyConfig) {
})
.use(require("markdown-it-footnote"))
.use(require("markdown-it-attrs"))
.use(require("markdown-it-hashtag"))
.use(function(md){
md.renderer.rules.hashtag_open = function(tokens, idx) {
return '<a class="tag" onclick="toggleInlineTagSearch(this)">'
}
})
.use(require('markdown-it-mathjax3'), {
tex: {
inlineMath: [

View File

@ -11,10 +11,14 @@ const handler = async (event) => {
const index = lunrjs.Index.load(indexJson);
console.log('index made');
let results =
search[0] == "#" && search.length > 1
? index.search(`tags:${search.substring(1)}`)
: index.search(search);
let results;
if(search[0] == "#" && search.length > 1){
results = index.search(`tags:${search.substring(1)}`)
}else if(search.length > 2 && search[0] == ">" && search[1] == "#"){
results = index.search(`${search.substring(2)}`)
}else{
results = index.search(search);
}
results.forEach(r => {
r.title = data[r.ref].title;

11
package-lock.json generated
View File

@ -22,6 +22,7 @@
"markdown-it": "^12.3.2",
"markdown-it-attrs": "^4.1.6",
"markdown-it-footnote": "^3.0.3",
"markdown-it-hashtag": "^0.4.0",
"markdown-it-mathjax3": "^4.3.1",
"markdown-it-plantuml": "^1.4.1",
"markdown-it-task-checkbox": "^1.0.6"
@ -3437,6 +3438,11 @@
"resolved": "https://registry.npmjs.org/markdown-it-footnote/-/markdown-it-footnote-3.0.3.tgz",
"integrity": "sha512-YZMSuCGVZAjzKMn+xqIco9d1cLGxbELHZ9do/TSYVzraooV8ypsppKNmUJ0fVH5ljkCInQAtFpm8Rb3eXSrt5w=="
},
"node_modules/markdown-it-hashtag": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/markdown-it-hashtag/-/markdown-it-hashtag-0.4.0.tgz",
"integrity": "sha512-+VCMH+f4/Ud5wPEtcAMrlLbUrrGViwR9JvjPy//X3Z7ZG1j5nQuHtDLTGZfMhkqYTMY+cTZgZkVNBsXMfU93Yg=="
},
"node_modules/markdown-it-mathjax3": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz",
@ -8980,6 +8986,11 @@
"resolved": "https://registry.npmjs.org/markdown-it-footnote/-/markdown-it-footnote-3.0.3.tgz",
"integrity": "sha512-YZMSuCGVZAjzKMn+xqIco9d1cLGxbELHZ9do/TSYVzraooV8ypsppKNmUJ0fVH5ljkCInQAtFpm8Rb3eXSrt5w=="
},
"markdown-it-hashtag": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/markdown-it-hashtag/-/markdown-it-hashtag-0.4.0.tgz",
"integrity": "sha512-+VCMH+f4/Ud5wPEtcAMrlLbUrrGViwR9JvjPy//X3Z7ZG1j5nQuHtDLTGZfMhkqYTMY+cTZgZkVNBsXMfU93Yg=="
},
"markdown-it-mathjax3": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz",

View File

@ -35,6 +35,7 @@
"markdown-it": "^12.3.2",
"markdown-it-attrs": "^4.1.6",
"markdown-it-footnote": "^3.0.3",
"markdown-it-hashtag": "^0.4.0",
"markdown-it-mathjax3": "^4.3.1",
"markdown-it-plantuml": "^1.4.1",
"markdown-it-task-checkbox": "^1.0.6"

View File

@ -11,6 +11,17 @@
}
}
window.toggleInlineTagSearch=function(evt) {
console.log(evt.textContent);
const term = evt.textContent;
if(term){
window.document.getElementById('term').value = '>' + term.trim();
window.toggleSearch();
window.search();
}
}
window.toggleTagSearch=function(evt) {
console.log(evt.textContent);
const term = evt.textContent;