Compare commits
No commits in common. "51ba98f045ce8bfb63ecd67b4a417a695d9340e4" and "d4de923f1ef6addcda5ee5cfdd5c090b05f68ab1" have entirely different histories.
51ba98f045
...
d4de923f1e
2
Makefile
2
Makefile
@ -4,8 +4,6 @@ install:
|
|||||||
mkdir -p /opt/notes2web
|
mkdir -p /opt/notes2web
|
||||||
cp -r templates /opt/notes2web
|
cp -r templates /opt/notes2web
|
||||||
cp styles.css /opt/notes2web
|
cp styles.css /opt/notes2web
|
||||||
cp fuse.js /opt/notes2web
|
|
||||||
cp search.js /opt/notes2web
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -rf /usr/local/bin/notes2web.py /opt/notes2web
|
rm -rf /usr/local/bin/notes2web.py /opt/notes2web
|
||||||
|
46
notes2web.py
46
notes2web.py
@ -10,8 +10,6 @@ import pypandoc
|
|||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
TEXT_ARTICLE_TEMPLATE_FOOT = None
|
TEXT_ARTICLE_TEMPLATE_FOOT = None
|
||||||
TEXT_ARTICLE_TEMPLATE_HEAD = None
|
TEXT_ARTICLE_TEMPLATE_HEAD = None
|
||||||
@ -19,7 +17,6 @@ INDEX_TEMPLATE_FOOT = None
|
|||||||
INDEX_TEMPLATE_HEAD = None
|
INDEX_TEMPLATE_HEAD = None
|
||||||
EXTRA_INDEX_CONTENT = None
|
EXTRA_INDEX_CONTENT = None
|
||||||
|
|
||||||
|
|
||||||
def get_files(folder):
|
def get_files(folder):
|
||||||
markdown = []
|
markdown = []
|
||||||
plaintext = []
|
plaintext = []
|
||||||
@ -27,8 +24,6 @@ def get_files(folder):
|
|||||||
|
|
||||||
for root, folders, files in os.walk(folder):
|
for root, folders, files in os.walk(folder):
|
||||||
for filename in files:
|
for filename in files:
|
||||||
if '/.git' in root:
|
|
||||||
continue
|
|
||||||
name = os.path.join(root, filename)
|
name = os.path.join(root, filename)
|
||||||
if os.path.splitext(name)[1] == '.md':
|
if os.path.splitext(name)[1] == '.md':
|
||||||
markdown.append(name)
|
markdown.append(name)
|
||||||
@ -40,7 +35,6 @@ def get_files(folder):
|
|||||||
|
|
||||||
return markdown, plaintext, other
|
return markdown, plaintext, other
|
||||||
|
|
||||||
|
|
||||||
def get_dirs(folder):
|
def get_dirs(folder):
|
||||||
r = []
|
r = []
|
||||||
|
|
||||||
@ -49,7 +43,6 @@ def get_dirs(folder):
|
|||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def update_required(src_filename, output_filename):
|
def update_required(src_filename, output_filename):
|
||||||
return not os.path.exists(output_filename) or os.path.getmtime(src_filename) > os.path.getmtime(output_filename)
|
return not os.path.exists(output_filename) or os.path.getmtime(src_filename) > os.path.getmtime(output_filename)
|
||||||
|
|
||||||
@ -67,12 +60,9 @@ def get_args():
|
|||||||
parser.add_argument('-i', '--template-index-head', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexhead.html'))
|
parser.add_argument('-i', '--template-index-head', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexhead.html'))
|
||||||
parser.add_argument('-I', '--template-index-foot', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexfoot.html'))
|
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('-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('-e', '--extra-index-content', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/extra_index_content.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('-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('-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'))
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -102,7 +92,6 @@ def main(args):
|
|||||||
|
|
||||||
|
|
||||||
markdown_files, plaintext_files, other_files = get_files(args.notes)
|
markdown_files, plaintext_files, other_files = get_files(args.notes)
|
||||||
all_entries=[]
|
|
||||||
|
|
||||||
print(f"{args.index_article_names=}")
|
print(f"{args.index_article_names=}")
|
||||||
|
|
||||||
@ -116,12 +105,12 @@ def main(args):
|
|||||||
|
|
||||||
if os.path.basename(filename) in args.index_article_names:
|
if os.path.basename(filename) in args.index_article_names:
|
||||||
output_filename = os.path.join(
|
output_filename = os.path.join(
|
||||||
os.path.dirname(re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes', filename))),
|
os.path.dirname(re.sub(f"^{args.notes.name}", args.output_dir.name, filename)),
|
||||||
'index.html'
|
'index.html'
|
||||||
)
|
)
|
||||||
dirs_with_index_article.append(os.path.dirname(re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename)))
|
dirs_with_index_article.append(os.path.dirname(re.sub(f"^{args.notes.name}", args.output_dir.name, filename)))
|
||||||
else:
|
else:
|
||||||
output_filename = os.path.splitext(re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename))[0] + '.html'
|
output_filename = os.path.splitext(re.sub(f"^{args.notes.name}", args.output_dir.name, filename))[0] + '.html'
|
||||||
|
|
||||||
fm = frontmatter.load(filename)
|
fm = frontmatter.load(filename)
|
||||||
if isinstance(fm.get('tags'), list):
|
if isinstance(fm.get('tags'), list):
|
||||||
@ -137,11 +126,6 @@ def main(args):
|
|||||||
'title': fm.get('title')
|
'title': fm.get('title')
|
||||||
} ]
|
} ]
|
||||||
print(f"{output_filename=}")
|
print(f"{output_filename=}")
|
||||||
all_entries.append({
|
|
||||||
'path': str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
|
||||||
'title': fm.get('title'),
|
|
||||||
'tags': fm.get('tags')
|
|
||||||
})
|
|
||||||
|
|
||||||
if update_required(filename, output_filename) or args.force:
|
if update_required(filename, output_filename) or args.force:
|
||||||
html = pypandoc.convert_file(filename, 'html', extra_args=[f'--template={args.template}'])
|
html = pypandoc.convert_file(filename, 'html', extra_args=[f'--template={args.template}'])
|
||||||
@ -153,7 +137,7 @@ def main(args):
|
|||||||
print(f"{plaintext_files=}")
|
print(f"{plaintext_files=}")
|
||||||
for filename in plaintext_files:
|
for filename in plaintext_files:
|
||||||
title = os.path.basename(re.sub(f"^{args.notes.name}", args.output_dir.name, filename))
|
title = os.path.basename(re.sub(f"^{args.notes.name}", args.output_dir.name, filename))
|
||||||
output_filename = re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename) + '.html'
|
output_filename = re.sub(f"^{args.notes.name}", args.output_dir.name, filename) + '.html'
|
||||||
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
|
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
|
||||||
html = re.sub(r'\$title\$', title, TEXT_ARTICLE_TEMPLATE_HEAD)
|
html = re.sub(r'\$title\$', title, TEXT_ARTICLE_TEMPLATE_HEAD)
|
||||||
html = re.sub(r'\$h1title\$', title, html)
|
html = re.sub(r'\$h1title\$', title, html)
|
||||||
@ -164,21 +148,11 @@ def main(args):
|
|||||||
|
|
||||||
with open(output_filename, 'w+') as fp:
|
with open(output_filename, 'w+') as fp:
|
||||||
fp.write(html)
|
fp.write(html)
|
||||||
all_entries.append({
|
|
||||||
'path': str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
|
||||||
'title': title,
|
|
||||||
'tags': []
|
|
||||||
})
|
|
||||||
|
|
||||||
print(f"{other_files=}")
|
print(f"{other_files=}")
|
||||||
for filename in other_files:
|
for filename in other_files:
|
||||||
output_filename = re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename)
|
output_filename = re.sub(f"^{args.notes.name}", args.output_dir.name, filename)
|
||||||
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
|
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
|
||||||
all_entries.append({
|
|
||||||
'path': str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
|
||||||
'title': str(pathlib.Path(*pathlib.Path(output_filename).parts[1:])),
|
|
||||||
'tags': []
|
|
||||||
})
|
|
||||||
shutil.copyfile(filename, output_filename)
|
shutil.copyfile(filename, output_filename)
|
||||||
|
|
||||||
tagdir = os.path.join(args.output_dir, '.tags')
|
tagdir = os.path.join(args.output_dir, '.tags')
|
||||||
@ -257,16 +231,6 @@ def main(args):
|
|||||||
fp.write(html)
|
fp.write(html)
|
||||||
|
|
||||||
shutil.copyfile(args.stylesheet, os.path.join(args.output_dir.name, 'styles.css'))
|
shutil.copyfile(args.stylesheet, os.path.join(args.output_dir.name, 'styles.css'))
|
||||||
shutil.copyfile(args.fuse, os.path.join(args.output_dir.name, 'fuse.js'))
|
|
||||||
shutil.copyfile(args.searchjs, os.path.join(args.output_dir.name, 'search.js'))
|
|
||||||
with open(os.path.join(args.output_dir.name, 'index.html'), 'w+') as fp:
|
|
||||||
with open(args.home_index) as fp2:
|
|
||||||
html = re.sub(r'\$title\$', args.output_dir.parts[0], fp2.read())
|
|
||||||
html = re.sub(r'\$h1title\$', args.output_dir.parts[0], html)
|
|
||||||
|
|
||||||
html = re.sub(r'\$data\$', json.dumps(all_entries), html)
|
|
||||||
|
|
||||||
fp.write(html)
|
|
||||||
print(tag_dict)
|
print(tag_dict)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -40,8 +40,7 @@ Output of `notes2web.py --help`:
|
|||||||
usage: notes2web.py [-h] [-o OUTPUT_DIR] [-t TEMPLATE] [-H TEMPLATE_TEXT_HEAD]
|
usage: notes2web.py [-h] [-o OUTPUT_DIR] [-t TEMPLATE] [-H TEMPLATE_TEXT_HEAD]
|
||||||
[-f TEMPLATE_TEXT_FOOT] [-i TEMPLATE_INDEX_HEAD]
|
[-f TEMPLATE_TEXT_FOOT] [-i TEMPLATE_INDEX_HEAD]
|
||||||
[-I TEMPLATE_INDEX_FOOT] [-s STYLESHEET]
|
[-I TEMPLATE_INDEX_FOOT] [-s STYLESHEET]
|
||||||
[--home_index HOME_INDEX] [-e EXTRA_INDEX_CONTENT]
|
[-e EXTRA_INDEX_CONTENT] [-n INDEX_ARTICLE_NAMES]
|
||||||
[-n INDEX_ARTICLE_NAMES] [-F]
|
|
||||||
notes
|
notes
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
@ -56,11 +55,8 @@ optional arguments:
|
|||||||
-i TEMPLATE_INDEX_HEAD, --template-index-head TEMPLATE_INDEX_HEAD
|
-i TEMPLATE_INDEX_HEAD, --template-index-head TEMPLATE_INDEX_HEAD
|
||||||
-I TEMPLATE_INDEX_FOOT, --template-index-foot TEMPLATE_INDEX_FOOT
|
-I TEMPLATE_INDEX_FOOT, --template-index-foot TEMPLATE_INDEX_FOOT
|
||||||
-s STYLESHEET, --stylesheet STYLESHEET
|
-s STYLESHEET, --stylesheet STYLESHEET
|
||||||
--home_index HOME_INDEX
|
|
||||||
-e EXTRA_INDEX_CONTENT, --extra-index-content EXTRA_INDEX_CONTENT
|
-e EXTRA_INDEX_CONTENT, --extra-index-content EXTRA_INDEX_CONTENT
|
||||||
-n INDEX_ARTICLE_NAMES, --index-article-names INDEX_ARTICLE_NAMES
|
-n INDEX_ARTICLE_NAMES, --index-article-names INDEX_ARTICLE_NAMES
|
||||||
-F, --force Generate new output html even if source file was
|
|
||||||
modified before output html
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The command will generate a website in the `output-dir` directory (`./web` by default).
|
The command will generate a website in the `output-dir` directory (`./web` by default).
|
||||||
|
23
search.js
23
search.js
@ -1,23 +0,0 @@
|
|||||||
const fuse = new Fuse(data, {
|
|
||||||
keys: ['path', 'title', 'tags']
|
|
||||||
})
|
|
||||||
|
|
||||||
const searchBar = document.getElementById('search')
|
|
||||||
const results = document.getElementById('results')
|
|
||||||
|
|
||||||
function callback() {
|
|
||||||
console.log("called")
|
|
||||||
console.log(searchBar.value)
|
|
||||||
results.innerHTML = ''
|
|
||||||
fuse.search(searchBar.value).forEach(r => {
|
|
||||||
wrapper = document.createElement('div')
|
|
||||||
content = document.createElement('a')
|
|
||||||
content.innerHTML = r.item.title
|
|
||||||
content.href = r.item.path
|
|
||||||
wrapper.appendChild(content)
|
|
||||||
wrapper.className = "article"
|
|
||||||
results.appendChild(wrapper)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
searchBar.addEventListener('keyup', callback)
|
|
11
styles.css
11
styles.css
@ -72,14 +72,3 @@ blockquote {
|
|||||||
blockquote * {
|
blockquote * {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search {
|
|
||||||
padding: 1em;
|
|
||||||
margin: 1em;
|
|
||||||
font-size: 1em;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
#results {
|
|
||||||
overflow-x: scroll;
|
|
||||||
}
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-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>
|
|
||||||
<h1>$h1title$</h1>
|
|
||||||
<p>
|
|
||||||
These are my personal notes. Correctness is not guaranteed.
|
|
||||||
Browse <a href="/notes">here</a> or by tag <a href="/.tags">here</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<input placeholder="Search" id="search">
|
|
||||||
<div id="results">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
|
|
||||||
|
|
||||||
<script src="/fuse.js"> </script>
|
|
||||||
<script> const data = $data$ </script>
|
|
||||||
<script src="/search.js"> </script>
|
|
||||||
</body>
|
|
Reference in New Issue
Block a user