diff --git a/README.md b/README.md index f71ea41..269deae 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ This tool was made so I could write my content only in `gmi` and publish both a gemini capsule and a website. +For now, this is very rudimentary and things are bound to change, especially the way +I structure the directory where my content lives. + ## TODO - [X] concatenate header + gmi2html + footer @@ -11,12 +14,32 @@ gemini capsule and a website. - [X] write the `gen_gmi` function - [X] make the line "---\n" of the footer only present in the code, not in the footer file -- [X] make a config file for things like - - directories where files are supposed to be - - names of certain files - - the remote servers for the sync feature +- [-] make a config file for things like + - certain variables should be made `CONSTANT` in the `__init__.py` - [X] also update the "/gemlog/index.gmi" with the list of articles - [X] write the sync features - [X] test the `gen gmi` and `gen html` features - [ ] write tests for it - [ ] move config file to `~/.config` with placeholder values + - [X] check for a config file in `~/.config` +- [ ] maybe save the old Bash script somewhere for posterity ? + +## My setup +My current folder structure for my capsule+website looks something like this: + +``` +my-internet +├── assets +│ ├── favicon.ico +│ └── style.css +├── content +│ ├── gemlog +│ │ └── index.gmi +│ ├── index.gmi +│ └── projects.gmi +├── footer.gmi +├── html-output +└── html-parts + ├── footer-part.html + └── header-part.html +``` diff --git a/config.json b/config.json new file mode 100644 index 0000000..d5a01bb --- /dev/null +++ b/config.json @@ -0,0 +1,11 @@ +{ + "workdir" : "where/your/sources/live", + "dir_assets" : "assets", + "dir_source" : "content", + "dir_helper" : "html-parts", + "dir_o_html" : "html-output", + "rem_gmi" : "your/remote/gemini/path", + "rem_html" : "your/remote/html/path", + "port" : "1312" +} + diff --git a/gmirator/__init__.py b/gmirator/__init__.py index e69de29..42b6130 100644 --- a/gmirator/__init__.py +++ b/gmirator/__init__.py @@ -0,0 +1,17 @@ +from pathlib import Path +import json + + +xdg_path = Path("~/.config/gmirator/config.json").expanduser() +cfg_file = xdg_path if xdg_path.exists() else "config.json" +with open(cfg_file) as f: + config = json.load(f) + +WORKDIR = Path(config["workdir"]) +DIR_ASSETS = WORKDIR / config["dir_assets"] +DIR_SOURCE = WORKDIR / config["dir_source"] +DIR_HELPER = WORKDIR / config["dir_helper"] +DIR_O_HTML = WORKDIR / config["dir_o_html"] +GMI_FOOTER = WORKDIR / "footer.gmi" + +RPORT = config["port"] diff --git a/gmirator/generate.py b/gmirator/generate.py index 9cc96cc..84a932d 100644 --- a/gmirator/generate.py +++ b/gmirator/generate.py @@ -3,26 +3,22 @@ import re import shutil from io import TextIOWrapper from pathlib import Path +from gmirator import ( + DIR_ASSETS, + DIR_SOURCE, + DIR_HELPER, + DIR_O_HTML, + GMI_FOOTER +) -import json - -config_path = "config.json" -with open(config_path) as f: - config = json.load(f) app = typer.Typer(help="generates your gmi and html files") -WORKDIR = Path(config["workdir"]) -DIR_ASSETS = WORKDIR / config["dir_assets"] -DIR_SOURCE = WORKDIR / config["dir_source"] -DIR_HELPER = WORKDIR / config["dir_helper"] -DIR_O_HTML = WORKDIR / config["dir_o_html"] - @app.command("gmi") def gen_gmi(): print("Generating GMI files...") make_index([DIR_SOURCE / "index.gmi", DIR_SOURCE / "gemlog/index.gmi"]) - make_footer(WORKDIR / "footer.gmi", DIR_SOURCE) + make_footer(GMI_FOOTER, DIR_SOURCE) print("Done!") def make_index(listing: list[Path]): diff --git a/gmirator/synchronise.py b/gmirator/synchronise.py index 31b0603..c29b07e 100644 --- a/gmirator/synchronise.py +++ b/gmirator/synchronise.py @@ -1,14 +1,7 @@ import typer import subprocess -from pathlib import Path import shlex -import json - -config_path = "config.json" -with open(config_path) as f: - config = json.load(f) -WORKDIR = Path(config["workdir"]) -RPORT = config["port"] +from gmirator import WORKDIR, RPORT app = typer.Typer(help="syncs your files with configured remote")