Compare commits
28 Commits
d147e56080
...
dev
Author | SHA1 | Date | |
---|---|---|---|
9e58be3a01
|
|||
496216568e
|
|||
2b8874106f
|
|||
b35e868850
|
|||
485022a1a6
|
|||
dbe652f531
|
|||
334cf824c7
|
|||
20885c5d03
|
|||
04609095d8
|
|||
15411335e9
|
|||
f301e83163
|
|||
98310897d4
|
|||
9323aeab53
|
|||
5c5f6ab89d
|
|||
ab618e77c1
|
|||
2f4ba8bba2
|
|||
117f1ee6ee
|
|||
a5341e770c
|
|||
b9404c206c
|
|||
6d10130155
|
|||
c5e2140738
|
|||
e331e4ce97
|
|||
e0471c8508
|
|||
0d2889252c
|
|||
c2b21e340e
|
|||
dbe7286936
|
|||
a647a6ab19
|
|||
23f81a28d8
|
6
Makefile
6
Makefile
@@ -1,11 +1,13 @@
|
||||
install:
|
||||
cp notes2web.py /usr/local/bin
|
||||
cp notes2web.py n2w_add_uuid.py /usr/local/bin
|
||||
pip3 install -r requirements.txt
|
||||
mkdir -p /opt/notes2web
|
||||
cp -r templates /opt/notes2web
|
||||
cp styles.css /opt/notes2web
|
||||
cp fuse.js /opt/notes2web
|
||||
cp search.js /opt/notes2web
|
||||
cp toc_search.js /opt/notes2web
|
||||
cp permalink.js /opt/notes2web
|
||||
|
||||
uninstall:
|
||||
rm -rf /usr/local/bin/notes2web.py /opt/notes2web
|
||||
rm -rf /usr/local/bin/notes2web.py /usr/local/bin/n2w_add_uuid.py /opt/notes2web
|
||||
|
51
n2w_add_uuid.py
Executable file
51
n2w_add_uuid.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import editfrontmatter
|
||||
import frontmatter
|
||||
import pathlib
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
def get_args():
|
||||
""" Get command line arguments """
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filename', type=pathlib.Path)
|
||||
parser.add_argument('--template',
|
||||
default=pathlib.Path("/opt/notes2web/templates/n2w_add_uuid_frontmatter_template"),
|
||||
type=pathlib.Path
|
||||
)
|
||||
parser.add_argument('-w', '--write', action='store_true',
|
||||
help='write to file instead of stdout')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main(args):
|
||||
""" Entry point for script """
|
||||
with open(args.template) as fp:
|
||||
template_str=fp.read()
|
||||
|
||||
with open(args.filename) as fp:
|
||||
fm_pre = frontmatter.load(fp)
|
||||
|
||||
processor = editfrontmatter.EditFrontMatter(file_path=args.filename, template_str=template_str)
|
||||
fm_data = fm_pre.metadata
|
||||
if 'uuid' not in fm_data.keys():
|
||||
fm_data['uuid'] = str(uuid.uuid4())
|
||||
|
||||
processor.run(fm_data)
|
||||
|
||||
if args.write:
|
||||
with open(args.filename, 'w') as fp:
|
||||
fp.write(processor.dumpFileData())
|
||||
else:
|
||||
print(processor.dumpFileData())
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
sys.exit(main(get_args()))
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
43
notes2web.py
43
notes2web.py
@@ -10,7 +10,7 @@ import pathlib
|
||||
import pypandoc
|
||||
import shutil
|
||||
import os
|
||||
import re
|
||||
import regex as re
|
||||
import json
|
||||
|
||||
|
||||
@@ -77,15 +77,19 @@ def git_filehistory(working_dir, filename):
|
||||
if filehistory == "":
|
||||
filehistory = ["This file has no history (it may not be part of the git repository)."]
|
||||
|
||||
filehistory = [ x.replace("<", "<").replace(">", ">") for x in filehistory]
|
||||
|
||||
filehistory = "<pre>\n" + "</pre><pre>\n".join(filehistory) + "</pre>"
|
||||
|
||||
return filehistory
|
||||
|
||||
|
||||
def get_dirs(folder):
|
||||
def get_dirs_to_index(folder):
|
||||
r = []
|
||||
|
||||
for root, folders, files in os.walk(folder):
|
||||
if pathlib.Path(os.path.join(root, folder)).is_relative_to(folder.joinpath('permalink')):
|
||||
continue
|
||||
[r.append(os.path.join(root, folder)) for folder in folders]
|
||||
|
||||
return r
|
||||
@@ -109,11 +113,15 @@ def get_args():
|
||||
parser.add_argument('-I', '--template-index-foot', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexfoot.html'))
|
||||
parser.add_argument('-s', '--stylesheet', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/styles.css'))
|
||||
parser.add_argument('--home_index', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/home_index.html'))
|
||||
parser.add_argument('--permalink_index', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/permalink_index.html'))
|
||||
parser.add_argument('-e', '--extra-index-content', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/extra_index_content.html'))
|
||||
parser.add_argument('-n', '--index-article-names', action='append', default=['index.md'])
|
||||
parser.add_argument('-F', '--force', action="store_true", help="Generate new output html even if source file was modified before output html")
|
||||
parser.add_argument('--fuse', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/fuse.js'))
|
||||
parser.add_argument('--searchjs', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/search.js'))
|
||||
parser.add_argument('--permalinkjs', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/permalink.js'))
|
||||
parser.add_argument('--tocsearchjs', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/toc_search.js'))
|
||||
parser.add_argument('--toc-depth', type=int, default=6, dest='toc_depth')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -152,6 +160,7 @@ def main(args):
|
||||
all_entries=[]
|
||||
dirs_with_index_article = []
|
||||
tag_dict = {}
|
||||
permalink_to_filepath = {}
|
||||
|
||||
print(f"{markdown_files=}")
|
||||
for filename in markdown_files:
|
||||
@@ -188,19 +197,25 @@ def main(args):
|
||||
header_lines.append(" ".join(line.split(" ")[1:]))
|
||||
|
||||
all_entries.append({
|
||||
'path': str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
||||
'path': '/' + str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
||||
'title': fm.get('title') or pathlib.Path(filename).name,
|
||||
'tags': fm.get('tags'),
|
||||
'headers': header_lines
|
||||
'headers': header_lines,
|
||||
'uuid': fm.get('uuid')
|
||||
})
|
||||
|
||||
if 'uuid' in fm.keys():
|
||||
permalink_to_filepath[fm['uuid']] = all_entries[-1]['path']
|
||||
|
||||
# update file if required
|
||||
if update_required(filename, output_filename) or args.force:
|
||||
filehistory = git_filehistory(args.notes, filename)
|
||||
html = pypandoc.convert_file(filename, 'html', extra_args=[
|
||||
f'--template={args.template}',
|
||||
'-V', f'filehistory={filehistory}',
|
||||
'-V', f'licenseFull={notes_license}'
|
||||
'-V', f'licenseFull={notes_license}',
|
||||
'--mathjax',
|
||||
'--toc', f'--toc-depth={args.toc_depth}'
|
||||
])
|
||||
pathlib.Path(output_filename).parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -270,7 +285,7 @@ def main(args):
|
||||
|
||||
|
||||
|
||||
dirs_to_index = [args.output_dir.name] + get_dirs(args.output_dir)
|
||||
dirs_to_index = [args.output_dir.name] + get_dirs_to_index(args.output_dir)
|
||||
print(f"{dirs_to_index=}")
|
||||
print(f"{dirs_with_index_article=}")
|
||||
|
||||
@@ -327,11 +342,11 @@ def main(args):
|
||||
|
||||
for entry in indexentries:
|
||||
html += (
|
||||
'<div class="article">'
|
||||
f'<a href="{entry["path"]}">'
|
||||
'<li class="article">'
|
||||
f'<a href="{entry["path"]}"><p>'
|
||||
f'{entry["title"]}{"/" if entry["isdirectory"] else ""}'
|
||||
'</a>'
|
||||
'</div>'
|
||||
'</p></a>'
|
||||
'</li>'
|
||||
)
|
||||
html += INDEX_TEMPLATE_FOOT
|
||||
|
||||
@@ -341,6 +356,8 @@ def main(args):
|
||||
shutil.copyfile(args.stylesheet, args.output_dir.joinpath('styles.css'))
|
||||
shutil.copyfile(args.fuse, args.output_dir.joinpath('fuse.js'))
|
||||
shutil.copyfile(args.searchjs, args.output_dir.joinpath('search.js'))
|
||||
shutil.copyfile(args.tocsearchjs, args.output_dir.joinpath('toc_search.js'))
|
||||
shutil.copyfile(args.permalinkjs, args.output_dir.joinpath('permalink.js'))
|
||||
with open(args.output_dir.joinpath('index.html'), 'w+') as fp:
|
||||
with open(args.home_index) as fp2:
|
||||
html = re.sub(r'\$title\$', args.output_dir.parts[0], fp2.read())
|
||||
@@ -348,6 +365,12 @@ def main(args):
|
||||
|
||||
html = re.sub(r'\$data\$', json.dumps(all_entries), html)
|
||||
|
||||
fp.write(html)
|
||||
permalink_dir = args.output_dir.joinpath('permalink')
|
||||
permalink_dir.mkdir(exist_ok=True)
|
||||
with open(args.permalink_index) as fp:
|
||||
html = re.sub(r'\$data\$', json.dumps(permalink_to_filepath), fp.read())
|
||||
with open(permalink_dir.joinpath('index.html'), 'w+') as fp:
|
||||
fp.write(html)
|
||||
print(tag_dict)
|
||||
|
||||
|
8
permalink.js
Normal file
8
permalink.js
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const MANUAL_REDIRECT = document.getElementById('manual_redirect');
|
||||
|
||||
const newLocation = data[new URLSearchParams(window.location.search).get('uuid')];
|
||||
|
||||
MANUAL_REDIRECT.href = newLocation;
|
||||
window.location = newLocation;
|
13
readme.md
13
readme.md
@@ -37,6 +37,7 @@ doing it for me:
|
||||
- `tags` --- A YAML list of tags which the article relates to - this is used for browsing and also
|
||||
searching
|
||||
- `title` --- The title of the article
|
||||
- `uuid` --- A unique identifier used for permalinks. More below.
|
||||
|
||||
- notes2web indexes [ATX-style headings](https://pandoc.org/MANUAL.html#atx-style-headings) for
|
||||
searching
|
||||
@@ -46,6 +47,18 @@ doing it for me:
|
||||
This is optional but if you would like to add a license you can find one
|
||||
[here](https://choosealicense.com).
|
||||
|
||||
### Permalinks
|
||||
|
||||
Permalinks are currently rather basic and requires JavaScript to be enabled on the local computer.
|
||||
In order to identify documents between file changes, a unique identifier is used to identify a file.
|
||||
|
||||
This unique identifier can be generated using the `uuidgen` command in the `uuid-runtime` package or
|
||||
`str(uuid.uuid())` in the `uuid` python package.
|
||||
|
||||
The included `n2w_add_uuid.py` will add a UUID to a markdown file which does not have a UUID in it
|
||||
already.
|
||||
Combine it with `find` to UUIDify all your markdown files (but make a backup first).
|
||||
|
||||
## CLI Usage
|
||||
|
||||
```
|
||||
|
@@ -1,6 +1,11 @@
|
||||
beautifulsoup4==4.9.3
|
||||
editfrontmatter==0.0.1
|
||||
Jinja2==3.0.3
|
||||
MarkupSafe==2.1.0
|
||||
oyaml==1.0
|
||||
pypandoc==1.5
|
||||
python-frontmatter==1.0.0
|
||||
python-magic==0.4.24
|
||||
PyYAML==5.4.1
|
||||
regex==2021.11.10
|
||||
soupsieve==2.2.1
|
||||
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 340 KiB |
31
search.js
31
search.js
@@ -4,7 +4,24 @@ const TAGS = "tags"
|
||||
const TITLE = "title"
|
||||
|
||||
const fuse = new Fuse(data, {
|
||||
keys: [ HEADERS, PATH, TAGS, TITLE ],
|
||||
keys: [
|
||||
{
|
||||
name: HEADERS,
|
||||
weight: 2
|
||||
},
|
||||
{
|
||||
name: PATH,
|
||||
weight: 0.5
|
||||
},
|
||||
{
|
||||
name: TAGS,
|
||||
weight: 1.5
|
||||
},
|
||||
{
|
||||
name: TITLE,
|
||||
weight: 1.5
|
||||
}
|
||||
],
|
||||
includeMatches: true
|
||||
})
|
||||
|
||||
@@ -80,7 +97,17 @@ searchBar.addEventListener('keyup', e => {
|
||||
}
|
||||
updateResults()
|
||||
})
|
||||
|
||||
searchBar.addEventListener('change', updateResults)
|
||||
resultsMax.addEventListener('keyup', updateResults)
|
||||
resultsMax.addEventListener('change', updateResults)
|
||||
updateResults()
|
||||
|
||||
const searchParams = new URL(window.location.href).searchParams;
|
||||
searchBar.value = searchParams.get('q');
|
||||
updateResults();
|
||||
|
||||
console.log(results)
|
||||
|
||||
if (searchParams.has('lucky')) {
|
||||
window.location.href = results[0].item.path;
|
||||
}
|
||||
|
176
styles.css
176
styles.css
@@ -1,95 +1,25 @@
|
||||
@import url("https://styles.alv.cx/base.css");
|
||||
@import url("https://styles.alv.cx/modules/search.css");
|
||||
@import url("https://styles.alv.cx/modules/buttonlist.css");
|
||||
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
h1 { font-size: 2.5em }
|
||||
h2 { font-size: 2em;}
|
||||
h3 { font-size: 1.5em; }
|
||||
|
||||
body {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
color: #454545;
|
||||
font-size: 16px;
|
||||
margin: 2em auto;
|
||||
max-width: 800px;
|
||||
padding: 1em;
|
||||
line-height: 1.4;
|
||||
text-align: justify;
|
||||
background-color: #fefefe;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
a { color: #07a; }
|
||||
a:visited { color: #941352; }
|
||||
|
||||
img[class="centered"] {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 1em auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
th, td {
|
||||
padding: 1em;
|
||||
border: 1px solid #454545;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
pre {
|
||||
background-color: #d9d9d9 ;
|
||||
color: #000;
|
||||
padding: 1em;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
|
||||
details {
|
||||
padding: 1em 0 1em 0;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
figcaption {
|
||||
margin: 0 auto;
|
||||
width: max-content;
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.article {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border-left: 0.4em solid #454545;
|
||||
margin-left: 0;
|
||||
padding-left: 1em;
|
||||
padding-top: 0.5em;
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
|
||||
blockquote * {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#searchWrapper > input {
|
||||
padding: 1em;
|
||||
margin: 1em 0.5em 1em 0.5em;
|
||||
font-size: 1em;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
#searchWrapper {
|
||||
display: flex
|
||||
}
|
||||
|
||||
#search { flex-grow: 9 }
|
||||
|
||||
#results {
|
||||
overflow-x: scroll;
|
||||
}
|
||||
|
||||
.smallText {
|
||||
font-size: 0.7em;
|
||||
}
|
||||
@@ -102,20 +32,80 @@ blockquote * {
|
||||
background-color: #86c1b9;
|
||||
}
|
||||
|
||||
#sidebar > #header { padding-bottom: 1em; color: #656565;}
|
||||
|
||||
#header > * {
|
||||
margin: 0;
|
||||
padding: 0
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
kbd {
|
||||
background-color: #d9d9d9;
|
||||
border-radius: 0.25em;
|
||||
padding: 0.2em;
|
||||
box-shadow: 0.15em 0.15em 0 #c9c9c9;
|
||||
margin-left: 0.2em;
|
||||
margin-right: 0.2em;
|
||||
#contentWrapper {
|
||||
display: flex
|
||||
}
|
||||
|
||||
|
||||
#sidebar {
|
||||
position: sticky;
|
||||
top: 10vh;
|
||||
height: 80vh;
|
||||
max-width: 30em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 20em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
#content {
|
||||
margin: 0 auto;
|
||||
width: 60em;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
#commitlog, #license { padding: 0; }
|
||||
|
||||
#toc {
|
||||
overflow-y: scroll;
|
||||
overflow-x: visible;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
#sidebar,
|
||||
#toc li > a {
|
||||
color: #656565;
|
||||
}
|
||||
|
||||
#toc li, ul#articlelist { list-style: none; }
|
||||
#toc ul, ul#articlelist { margin-left: 0.75em ; padding-left: 0.75em; }
|
||||
#toc ul, ul#articlelist { border-left: 1px solid #b3b3b3;}
|
||||
#toc > ul { padding; none; padding: 0; margin: 0; border: none;max-width: 100%;}
|
||||
li { padding: 0 !important; }
|
||||
|
||||
#toc li > a,
|
||||
ul#articlelist > a{
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
transition: 0.5s;
|
||||
padding: 0.5em;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
#toc li > a:hover,
|
||||
ul#articlelist li a:hover {
|
||||
background: #d9d9d9;
|
||||
color: black;
|
||||
}
|
||||
|
||||
mjx-container {
|
||||
overflow-x: scroll;
|
||||
}
|
||||
|
||||
@media (max-width: 60em) {
|
||||
/* CSS that should be displayed if width is equal to or less than 60em goes here */
|
||||
#contentWrapper { flex-direction: column }
|
||||
#sidebar { position: static; width: 100%; max-width: none; }
|
||||
}
|
||||
|
||||
|
||||
/* ==============================================================================
|
||||
Pygments (pandoc built-in style)
|
||||
==============================================================================
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
@@ -9,34 +9,48 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header">
|
||||
<p style="font-size: 0.7em"> tags: [
|
||||
$for(tags)$
|
||||
<a href="/.tags/$tags$.html">$tags$</a>$sep$,
|
||||
$endfor$
|
||||
]</p>
|
||||
<p class="smallText">
|
||||
written by $for(author)$$author$$sep$, $endfor$
|
||||
</p>
|
||||
<p class="smallText">
|
||||
syntax highlighting based on <a href="https://pygments.org/">Pygments'</a> default
|
||||
colors
|
||||
</p>
|
||||
<p class="smallText">
|
||||
page generated by <a href="https://git.alv.cx/alvierahman90/notes2web">notes2web</a>
|
||||
</p>
|
||||
<details id="commitLog">
|
||||
<summary class="smallText">
|
||||
Commit log (file history)
|
||||
</summary>
|
||||
$filehistory$
|
||||
</details>
|
||||
<details>
|
||||
<summary class="smallText">
|
||||
License
|
||||
</summary>
|
||||
<pre>$licenseFull$</pre>
|
||||
</details>
|
||||
<div>
|
||||
$body$
|
||||
<div id="contentWrapper">
|
||||
<div id="sidebar">
|
||||
<div id="header">
|
||||
<p class="smallText">
|
||||
<a href="/permalink?uuid=$uuid$">permalink</a>
|
||||
</p>
|
||||
<p class="smallText"> tags: [
|
||||
$for(tags)$
|
||||
<a href="/.tags/$tags$.html">$tags$</a>$sep$,
|
||||
$endfor$
|
||||
]</p>
|
||||
<p class="smallText">
|
||||
written by $for(author)$$author$$sep$, $endfor$
|
||||
</p>
|
||||
<p class="smallText">
|
||||
syntax highlighting based on <a href="https://pygments.org/">Pygments'</a> default
|
||||
colors
|
||||
</p>
|
||||
<p class="smallText">
|
||||
page generated by <a href="https://git.alv.cx/alvierahman90/notes2web">notes2web</a>
|
||||
</p>
|
||||
</div>
|
||||
<h3>Table of Contents</h3>
|
||||
<input id="search" placeholder="Search table of contents" />
|
||||
<div id="toc">$toc$</div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<details id="commitLog">
|
||||
<summary class="smallText">
|
||||
Commit log (file history)
|
||||
</summary>
|
||||
$filehistory$
|
||||
</details>
|
||||
<details id="license">
|
||||
<summary class="smallText">
|
||||
License
|
||||
</summary>
|
||||
<pre>$licenseFull$</pre>
|
||||
</details>
|
||||
$body$
|
||||
</div>
|
||||
</div>
|
||||
<script src="/fuse.js"> </script>
|
||||
<script src="/toc_search.js"> </script>
|
||||
</body>
|
||||
|
@@ -1,11 +1,12 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
<title>$title$</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1>$h1title$</h1>
|
||||
<p>
|
||||
These are my personal notes. Correctness is not guaranteed.
|
||||
@@ -13,7 +14,7 @@ Browse <a href="/notes">here</a> or by tag <a href="/.tags">here</a>.
|
||||
</p>
|
||||
|
||||
<div id="searchWrapper">
|
||||
<input placeholder="Search" id="search">
|
||||
<input placeholder="Search" id="search" autofocus>
|
||||
<input type="number" id="resultsMax" min="0" value="5">
|
||||
</div>
|
||||
<p class="smallText" style="margin-top: 0; text-align: center;"> Press <kbd>Enter</kbd> to open first result or <kbd>Shift</kbd>+<kbd>Enter</kbd> to open in new tab</p>
|
||||
@@ -21,7 +22,7 @@ Browse <a href="/notes">here</a> or by tag <a href="/.tags">here</a>.
|
||||
</div>
|
||||
|
||||
<p class="smallText"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
||||
|
||||
</div>
|
||||
<script src="/fuse.js"> </script>
|
||||
<script> const data = $data$ </script>
|
||||
<script src="/search.js"> </script>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
@@ -7,7 +7,8 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>$h1title$</h1>
|
||||
<div id="content">
|
||||
$body$
|
||||
|
||||
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
||||
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -1,2 +1,4 @@
|
||||
</ul>
|
||||
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
@@ -7,6 +7,8 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1>$title$</h1>
|
||||
$extra_content$
|
||||
<div class="article"><a href="..">../</a></div>
|
||||
<ul class="buttonlist">
|
||||
<li class="article"><a href=".."><p>../</p></a></li>
|
||||
|
@@ -1,7 +0,0 @@
|
||||
<li>
|
||||
<a href="$filepath$"> $if(title)$
|
||||
$title$
|
||||
$else$
|
||||
no title ($filepath$)
|
||||
$endif$</a>
|
||||
</li>
|
5
templates/n2w_add_uuid_frontmatter_template
Normal file
5
templates/n2w_add_uuid_frontmatter_template
Normal file
@@ -0,0 +1,5 @@
|
||||
author: {{ author }}
|
||||
date: {{ date }}
|
||||
title: {{ title }}
|
||||
tags: {{ tags }}
|
||||
uuid: {{ uuid }}
|
19
templates/permalink_index.html
Normal file
19
templates/permalink_index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<p>
|
||||
You should be being redirected...
|
||||
Otherwise, click <a id="manual_redirect">here</a>.
|
||||
</p>
|
||||
|
||||
<p class="smallText"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
||||
</div>
|
||||
<script> const data = $data$ </script>
|
||||
<script src="/permalink.js"> </script>
|
||||
</body>
|
@@ -1,2 +1,3 @@
|
||||
</pre>
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" />
|
||||
<link rel="stylesheet" type="text/css" href="/styles.css" />
|
||||
@@ -7,6 +7,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<div id="header">
|
||||
<p class="smallText">
|
||||
page generated by <a href="https://git.alv.cx/alvierahman90/notes2web">notes2web</a>
|
||||
|
94
toc_search.js
Normal file
94
toc_search.js
Normal file
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
var raw_html_tree = document.getElementById('toc').firstChild.cloneNode(true);
|
||||
|
||||
function createSearchable(el) {
|
||||
var par = el.parentElement;
|
||||
var obj = el.cloneNode(true);
|
||||
|
||||
while(par != raw_html_tree) {
|
||||
var clone_parent = par.cloneNode(true);
|
||||
|
||||
while (clone_parent.firstChild != clone_parent.lastChild) {
|
||||
clone_parent.removeChild(clone_parent.lastChild);
|
||||
}
|
||||
console.log("obj.innerHTML: " + obj.innerHTML);
|
||||
console.log("clone_parent.firstChild.innerHTML: " + clone_parent.firstChild.innerHTML);
|
||||
if (obj.innerHTML != clone_parent.firstChild.innerHTML)
|
||||
clone_parent.appendChild(obj);
|
||||
|
||||
obj = clone_parent;
|
||||
par = par.parentElement;
|
||||
}
|
||||
|
||||
return {
|
||||
searchable: el.innerHTML,
|
||||
obj: obj
|
||||
};
|
||||
}
|
||||
|
||||
var searchables = [];
|
||||
Array(...raw_html_tree.getElementsByTagName('a'))
|
||||
.forEach(el => searchables.push(createSearchable(el)));
|
||||
|
||||
var fuse = new Fuse(searchables, { keys: [ 'searchable' ], includeMatches: true});
|
||||
var searchBar = document.getElementById('search');
|
||||
var resultsDiv = document.getElementById('toc');
|
||||
|
||||
function updateResults() {
|
||||
var ul = document.createElement('ul');
|
||||
resultsDiv.innerHTML = '';
|
||||
if (searchBar.value == '') {
|
||||
resultsDiv.appendChild(raw_html_tree);
|
||||
return;
|
||||
}
|
||||
var results = fuse.search(searchBar.value);
|
||||
|
||||
|
||||
results.forEach(r => {
|
||||
console.log(r)
|
||||
var content = r.item.obj
|
||||
var last_a = Array.from(r.item.obj.getElementsByTagName('a')).pop()
|
||||
|
||||
r.matches.reverse().every(match => {
|
||||
var display_match = match.value;
|
||||
if (match.indices.length >= 1) {
|
||||
match.indices.sort((a, b) => (b[1]-b[0])-(a[1]-a[0]));
|
||||
const indexPair = match.indices[0];
|
||||
const matching_slice = match.value.slice(indexPair[0], indexPair[1]+1);
|
||||
last_a.innerHTML = match.value.replace(
|
||||
matching_slice,
|
||||
'<span class="matchHighlight">' + matching_slice + '</span>'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
})
|
||||
|
||||
ul.appendChild(content);
|
||||
ul.appendChild(document.createElement('br'));
|
||||
})
|
||||
resultsDiv.appendChild(ul);
|
||||
}
|
||||
|
||||
searchBar.addEventListener('keyup', e => {
|
||||
// if user pressed enter
|
||||
if (e.keyCode === 13) {
|
||||
if (e.shiftKey) {
|
||||
window.open(results[0].item.path, '_blank');
|
||||
} else {
|
||||
window.location.href = results[0].item.path;
|
||||
}
|
||||
return;
|
||||
}
|
||||
updateResults();
|
||||
})
|
||||
|
||||
searchBar.addEventListener('change', updateResults);
|
||||
|
||||
const searchParams = new URL(window.location.href).searchParams;
|
||||
searchBar.value = searchParams.get('q');
|
||||
updateResults();
|
||||
|
||||
if (searchParams.has('lucky')) {
|
||||
window.location.href = results[0].item.path;
|
||||
}
|
Reference in New Issue
Block a user