From d147e5608017798708c656310e92313181533286 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Wed, 1 Sep 2021 18:26:18 +0100 Subject: [PATCH] Show contents of LICENSE --- notes2web.py | 14 +++++++++++++- readme.md | 4 ++++ templates/article.html | 7 +++++++ templates/textarticlehead.html | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/notes2web.py b/notes2web.py index bad6077..4448065 100755 --- a/notes2web.py +++ b/notes2web.py @@ -140,6 +140,13 @@ def main(args): args.output_dir.mkdir(parents=True, exist_ok=True) + notes_license = "This note has no copyright license.", + print(f"{notes_license=}") + license_path = args.notes.joinpath("LICENSE") + if license_path.exists(): + with open(license_path) as fp: + notes_license = fp.read() + markdown_files, plaintext_files, other_files = get_files(args.notes) all_entries=[] @@ -190,7 +197,11 @@ def main(args): # 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}']) + html = pypandoc.convert_file(filename, 'html', extra_args=[ + f'--template={args.template}', + '-V', f'filehistory={filehistory}', + '-V', f'licenseFull={notes_license}' + ]) pathlib.Path(output_filename).parent.mkdir(parents=True, exist_ok=True) with open(output_filename, 'w+') as fp: @@ -211,6 +222,7 @@ def main(args): html = re.sub(r'\$title\$', title, TEXT_ARTICLE_TEMPLATE_HEAD) html = re.sub(r'\$h1title\$', title, html) html = re.sub(r'\$raw\$', os.path.basename(filename), html) + html = re.sub(r'\$licenseFull\$', notes_license, html) html = html.replace('$filehistory$', filehistory) with open(filename) as fp: html += fp.read().replace("<", "<").replace(">", ">") diff --git a/readme.md b/readme.md index 81e7f69..6d922e4 100644 --- a/readme.md +++ b/readme.md @@ -41,6 +41,10 @@ doing it for me: - notes2web indexes [ATX-style headings](https://pandoc.org/MANUAL.html#atx-style-headings) for searching - notes2web attempts to display file history through the `git log` command +- notes2web looks for the plaintext file `LICENSE` in the root directory of your notes + + This is optional but if you would like to add a license you can find one + [here](https://choosealicense.com). ## CLI Usage diff --git a/templates/article.html b/templates/article.html index b156162..dc945b3 100644 --- a/templates/article.html +++ b/templates/article.html @@ -17,6 +17,7 @@ ]

written by $for(author)$$author$$sep$, $endfor$ +

syntax highlighting based on Pygments' default colors @@ -30,6 +31,12 @@ $filehistory$ +

+ + License + +
$licenseFull$
+
$body$ diff --git a/templates/textarticlehead.html b/templates/textarticlehead.html index 6049d1c..ee2c2ea 100644 --- a/templates/textarticlehead.html +++ b/templates/textarticlehead.html @@ -17,6 +17,12 @@ $filehistory$ +
+ + License + +
$licenseFull$
+

$title$

This file was not rendered by notes2web because it is a plaintext file, not a markdown