From 507c6e8dec18517ce83bca63c6c91505b9d2bb7d Mon Sep 17 00:00:00 2001 From: makeworld Date: Sun, 20 Dec 2020 00:31:14 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Wiki=20script,=20link=20to=20wik?= =?UTF-8?q?i=20on=20new=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 154 ++++++++++++++++++++++++++- CHANGELOG.md | 1 + contrib/gemini-wiki/README.md | 8 ++ contrib/gemini-wiki/main.py | 111 +++++++++++++++++++ contrib/gemini-wiki/requirements.txt | 1 + display/newtab.go | 9 +- 6 files changed, 278 insertions(+), 6 deletions(-) create mode 100644 contrib/gemini-wiki/README.md create mode 100644 contrib/gemini-wiki/main.py create mode 100644 contrib/gemini-wiki/requirements.txt diff --git a/.gitignore b/.gitignore index f184910..dceeb46 100644 --- a/.gitignore +++ b/.gitignore @@ -14,15 +14,15 @@ rec.yml # GIMP files *.xcf -# Created by https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows -# Edit at https://www.toptal.com/developers/gitignore?templates=code,go,linux,macos,windows + +# Created by https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows,python +# Edit at https://www.toptal.com/developers/gitignore?templates=code,go,linux,macos,windows,python ### Code ### .vscode/* -!.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json -!.vscode/extensions.json +*.code-workspace ### Go ### # Binaries for programs and plugins @@ -38,6 +38,9 @@ rec.yml # Output of the go coverage tool, specifically when used with LiteIDE *.out +# Dependency directories (remove the comment below to include it) +# vendor/ + ### Go Patch ### /vendor/ /Godeps/ @@ -66,6 +69,7 @@ rec.yml # Icon must end with two \r Icon + # Thumbnails ._* @@ -85,9 +89,149 @@ Network Trash Folder Temporary Items .apdisk +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + ### Windows ### # Windows thumbnail cache files Thumbs.db +Thumbs.db:encryptable ehthumbs.db ehthumbs_vista.db @@ -110,4 +254,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# End of https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows +# End of https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows,python diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a54b1..1bb1192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for Unicode in domain names (IDNs) - Unnecessarily encoded characters in URLs will be decoded (#138) - URLs are NFC-normalized before any processing (#138) +- Links to the wiki in the new tab ### Changed - Updated [go-gemini](https://github.com/makeworld-the-better-one/go-gemini) to v0.11.0 diff --git a/contrib/gemini-wiki/README.md b/contrib/gemini-wiki/README.md new file mode 100644 index 0000000..78f868f --- /dev/null +++ b/contrib/gemini-wiki/README.md @@ -0,0 +1,8 @@ +# gemini-wiki + +This folder contains a Python script that downloads the Amfora [wiki](https://github.com/makeworld-the-better-one/amfora/wiki) +and converts it to gemtext, incorporating the sidebar and footer as well. + +The script expects to be run inside the folder where the Gemini version of the wiki should be. + +The output of this script can be viewed at `gemini://makeworld.gq/amfora-wiki/`. \ No newline at end of file diff --git a/contrib/gemini-wiki/main.py b/contrib/gemini-wiki/main.py new file mode 100644 index 0000000..d6d0616 --- /dev/null +++ b/contrib/gemini-wiki/main.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 + +# Formatted with black. + +import shutil +import subprocess +import sys +import os +import md2gemini + +TMP_WIKI_CLONE = "/tmp/amfora.wiki" + + +def md2gem(markdown): + return md2gemini.md2gemini( + markdown, + links="copy", + plain=False, + strip_html=True, + md_links=True, + link_func=link_func, + ) + + +def link_func(link): + if "://" in link: + # Absolute URL + return link + + # Link to other wiki page + return link + ".gmi" + + +def run_cmd(*args): + proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + if proc.returncode != 0: + print( + "Command " + + " ".join(args) + + "failed with exit code " + + str(proc.returncode) + ) + print("Output was:") + print() + print(proc.stdout.decode()) + sys.exit(1) + + +# Delete leftover git repo +try: + shutil.rmtree(TMP_WIKI_CLONE) +except FileNotFoundError: + pass + +os.mkdir(TMP_WIKI_CLONE) + +run_cmd( + "git", + "clone", + "--depth", + "1", + "https://github.com/makeworld-the-better-one/amfora.wiki.git", + TMP_WIKI_CLONE, +) + +# Save special files + +with open(os.path.join(TMP_WIKI_CLONE, "_Footer.md"), "r") as f: + footer = md2gem(f.read()) + +# Get files +(_, _, files) = next(os.walk(TMP_WIKI_CLONE)) + +# Create list of pages +pages = "## Pages\n\n=>.. Home\n" +for file in files: + + if file in ["_Footer.md", "_Sidebar.md", "Home.md"]: + continue + if not file.endswith(".md"): + continue + pages += "=>" + file[:-2] + "gmi " + file[:-3].replace("-", " ") + "\n" + +pages += "\n\n" + +for file in files: + filepath = os.path.join(TMP_WIKI_CLONE, file) + + if file in ["_Footer.md", "_Sidebar.md"]: + continue + if not file.endswith(".md"): + # Could be a resource like an image file, copy it + shutil.copyfile(filepath, file) + continue + + # Markdown file + + with open(filepath, "r") as f: + gemtext = md2gem(f.read()) + + # Add title, sidebar, footer + gemtext = "# " + file[:-3].replace("-", " ") + "\n\n" + pages + gemtext + gemtext += "\n\n\n\n" + footer + + if file == "Home.md": + file = "index.md" + + new_name = file[:-2] + "gmi" + + with open(new_name, "w") as f: + f.write(gemtext) \ No newline at end of file diff --git a/contrib/gemini-wiki/requirements.txt b/contrib/gemini-wiki/requirements.txt new file mode 100644 index 0000000..996537c --- /dev/null +++ b/contrib/gemini-wiki/requirements.txt @@ -0,0 +1 @@ +md2gemini<2 \ No newline at end of file diff --git a/display/newtab.go b/display/newtab.go index fbc119b..433ebb2 100644 --- a/display/newtab.go +++ b/display/newtab.go @@ -17,11 +17,18 @@ You can customize this page by creating a gemtext file called newtab.gmi, in Amf Happy browsing! +## Internal Pages + => about:bookmarks Bookmarks => about:subscriptions Subscriptions +## Learn more about Amfora! + +=> https://github.com/makeworld-the-better-one/amfora Amfora homepage +=> https://github.com/makeworld-the-better-one/amfora/wiki Amfora Wiki [GitHub] +=> gemini://makeworld.gq/amfora-wiki/ Amfora Wiki [On Gemini!] + => //gemini.circumlunar.space Project Gemini -=> https://github.com/makeworld-the-better-one/amfora Amfora homepage [HTTPS] ` // Read the new tab content from a file if it exists or fallback to a default page.