Compare commits
6 Commits
a91f5dcdfc
...
main
Author | SHA1 | Date | |
---|---|---|---|
0f64ca5849
|
|||
8bd9173847
|
|||
dc4560c232
|
|||
da0d9db113
|
|||
98a6649a39
|
|||
0ae70aa2b3
|
4
Makefile
4
Makefile
@@ -1,14 +1,16 @@
|
||||
install:
|
||||
cp n2w_add_uuid.py /usr/local/bin
|
||||
sed "s/N2W_COMMIT = \"\"/N2W_COMMIT = \"$$(git rev-parse --short HEAD)\"/" notes2web.py > /usr/local/bin/notes2web.py
|
||||
pip3 install -r requirements.txt
|
||||
pip3 install -r requirements.txt --break-system-packages
|
||||
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 indexsearch.js /opt/notes2web
|
||||
cp toc_search.js /opt/notes2web
|
||||
cp permalink.js /opt/notes2web
|
||||
chmod +x /usr/local/bin/notes2web.py
|
||||
|
||||
uninstall:
|
||||
rm -rf /usr/local/bin/notes2web.py /usr/local/bin/n2w_add_uuid.py /opt/notes2web
|
||||
|
75
indexsearch.js
Normal file
75
indexsearch.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const HEADERS = "headers"
|
||||
const PATH = "path"
|
||||
const TAGS = "tags"
|
||||
const TITLE = "title"
|
||||
|
||||
const SEARCH_TIMEOUT_MS = 100
|
||||
var SEARCH_TIMEOUT_ID = -1
|
||||
|
||||
const fuse = new Fuse(data, {
|
||||
keys: [ 'title' ],
|
||||
ignoreLocation: true,
|
||||
threshhold: 0.4,
|
||||
minMatchCharLength: 0,
|
||||
})
|
||||
|
||||
const RESULTS_MAX = 15
|
||||
|
||||
const searchBar = document.getElementById('search')
|
||||
const resultsDiv = document.getElementById('searchResults')
|
||||
|
||||
var results = []
|
||||
|
||||
function updateResultsWithTimeout() {
|
||||
console.log("clearing timeout")
|
||||
if (SEARCH_TIMEOUT_ID) SEARCH_TIMEOUT_ID = clearTimeout(SEARCH_TIMEOUT_ID)
|
||||
SEARCH_TIMEOUT_ID = setTimeout(updateResults, SEARCH_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
function updateResults() {
|
||||
console.log("updating results")
|
||||
resultsDiv.innerHTML = ''
|
||||
if (searchBar.value) results = fuse.search(searchBar.value, { limit: RESULTS_MAX }).map(r => r.item)
|
||||
else results = data
|
||||
|
||||
results.forEach(r => {
|
||||
wrapper = document.createElement('li')
|
||||
wrapper.className = "article"
|
||||
|
||||
atag = document.createElement('a')
|
||||
atag.href = r.path
|
||||
|
||||
ptag = document.createElement('p')
|
||||
ptag.innerHTML = r.title + (r.isdirectory ? '/' : '')
|
||||
|
||||
atag.appendChild(ptag)
|
||||
wrapper.appendChild(atag)
|
||||
resultsDiv.appendChild(wrapper)
|
||||
})
|
||||
}
|
||||
|
||||
searchBar.addEventListener('keyup', e => {
|
||||
console.log(e)
|
||||
// if user pressed enter
|
||||
if (e.keyCode === 13) {
|
||||
if (e.shiftKey) {
|
||||
window.open(results[0].path, '_blank')
|
||||
} else {
|
||||
window.location.href = results[0].path
|
||||
}
|
||||
return
|
||||
}
|
||||
updateResultsWithTimeout()
|
||||
})
|
||||
|
||||
searchBar.addEventListener('change', updateResultsWithTimeout)
|
||||
|
||||
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].path;
|
||||
}
|
11
notes2web.py
11
notes2web.py
@@ -153,6 +153,7 @@ def get_args():
|
||||
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('--indexsearchjs', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/indexsearch.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')
|
||||
@@ -317,14 +318,13 @@ def main(args):
|
||||
html = re.sub(r'\$extra_content\$', '', html)
|
||||
|
||||
for entry in tag_dict[tag]:
|
||||
html += f"<div class=\"article\"><a href=\"/{entry['path']}\">{entry['title']}</a></div>"
|
||||
html += INDEX_TEMPLATE_FOOT
|
||||
entry['path'] = '/' + entry['path']
|
||||
html += f"<div class=\"article\"><a href=\"{entry['path']}\">{entry['title']}</a></div>"
|
||||
html += re.sub('\$data\$', json.dumps(tag_dict[tag]), INDEX_TEMPLATE_FOOT)
|
||||
|
||||
with open(tagdir.joinpath(f'{tag}.html'), 'w+') as fp:
|
||||
fp.write(html)
|
||||
|
||||
|
||||
|
||||
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=}")
|
||||
@@ -389,7 +389,7 @@ def main(args):
|
||||
'</p></a>'
|
||||
'</li>'
|
||||
)
|
||||
html += INDEX_TEMPLATE_FOOT
|
||||
html += re.sub(r'\$data\$', json.dumps(indexentries), INDEX_TEMPLATE_FOOT)
|
||||
|
||||
with open(directory.joinpath('index.html'), 'w+') as fp:
|
||||
fp.write(html)
|
||||
@@ -397,6 +397,7 @@ 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.indexsearchjs, args.output_dir.joinpath('indexsearch.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:
|
||||
|
12
readme.md
12
readme.md
@@ -1,3 +1,5 @@
|
||||
> notes2web is now called [gronk](https://github.com/alvierahman90/gronk) and development has moved
|
||||
|
||||
# notes2web
|
||||
|
||||
View your notes as a static html site. Browse a live sample of it [here](https://notes.alv.cx).
|
||||
@@ -22,13 +24,7 @@ doing it for me:
|
||||
|
||||
## Install
|
||||
|
||||
0. Install [Pandoc](https://pandoc.org/index.html) and [Pip](https://github.com/pypa/pip)
|
||||
|
||||
On arch:
|
||||
```
|
||||
# pacman -S pandoc python-pip
|
||||
```
|
||||
|
||||
0. Install [Pandoc](https://pandoc.org/index.html) and [Pip](https://github.com/pypa/pip), python3-dev, and a C compiler
|
||||
1. Run `make install` as root
|
||||
|
||||
## Things to Remember Whilst Writing Notes
|
||||
@@ -40,6 +36,8 @@ doing it for me:
|
||||
searching
|
||||
- `title` --- The title of the article
|
||||
- `uuid` --- A unique identifier used for permalinks. More below.
|
||||
- `lecture_slides` --- a list of paths pointing to lecture slides used while taking notes
|
||||
- `lecture_notes` --- a list of paths pointing to other notes used while taking notes
|
||||
|
||||
- notes2web indexes [ATX-style headings](https://pandoc.org/MANUAL.html#atx-style-headings) for
|
||||
searching
|
||||
|
@@ -6,6 +6,6 @@ oyaml==1.0
|
||||
pypandoc==1.5
|
||||
python-frontmatter==1.0.0
|
||||
python-magic==0.4.24
|
||||
PyYAML==5.4.1
|
||||
PyYAML==5.3.1
|
||||
regex==2021.11.10
|
||||
soupsieve==2.2.1
|
||||
|
@@ -21,6 +21,21 @@
|
||||
<p class="smallText metadata">
|
||||
title: $title$
|
||||
</p>
|
||||
$if(lecture_slides)$
|
||||
<p class="smallText metadata"> lecture_slides: [
|
||||
$for(lecture_slides)$
|
||||
<a href="$lecture_slides$">$lecture_slides$</a>$sep$,
|
||||
$endfor$
|
||||
]</p>
|
||||
$endif$
|
||||
$if(lecture_notes)$
|
||||
<p class="smallText metadata"> lecture_notes: [
|
||||
$for(lecture_notes)$
|
||||
<a href="$lecture_notes$">$lecture_notes$</a>$sep$,
|
||||
$endfor$
|
||||
]</p>
|
||||
$endif$
|
||||
|
||||
<p class="smallText metadata">
|
||||
uuid: $uuid$ (<a href="/permalink?uuid=$uuid$">permalink</a>)
|
||||
</p>
|
||||
|
@@ -1,4 +1,7 @@
|
||||
</ul>
|
||||
<p style="font-size: 0.7em;"> 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="/indexsearch.js"> </script>
|
||||
</body>
|
||||
|
@@ -10,5 +10,12 @@
|
||||
<div id="content">
|
||||
<h1>$title$</h1>
|
||||
$extra_content$
|
||||
<ul class="buttonlist">
|
||||
<div id="searchWrapper">
|
||||
<input id="search" placeholder="search" autocomplete="off" autofocus>
|
||||
</div>
|
||||
<p class="searchSmallText" style="margin-top: 0; text-align: center">
|
||||
Press (<kbd>Shift</kbd>+)<kbd>Enter</kbd> to open first result (in new tab)
|
||||
</p>
|
||||
|
||||
<ul id="searchResults" class="buttonlist">
|
||||
<li class="article"><a href=".."><p>../</p></a></li>
|
||||
|
Reference in New Issue
Block a user