📝 Wiki script, link to wiki on new tab

This commit is contained in:
makeworld 2020-12-20 00:31:14 -05:00
parent 95f077c083
commit 507c6e8dec
6 changed files with 278 additions and 6 deletions

154
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -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/`.

111
contrib/gemini-wiki/main.py Normal file
View File

@ -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)

View File

@ -0,0 +1 @@
md2gemini<2

View File

@ -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.