refactor of how the configs are managed
more constants, in the same place, imported only in needed files
This commit is contained in:
parent
0d81f3fa3b
commit
ffc3c7cdcf
5 changed files with 64 additions and 24 deletions
31
README.md
31
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
|
||||
```
|
||||
|
|
11
config.json
Normal file
11
config.json
Normal file
|
@ -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"
|
||||
}
|
||||
|
|
@ -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"]
|
|
@ -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]):
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue