From d7090b836a2c58669d9f39a6158966515800a02a Mon Sep 17 00:00:00 2001 From: stev Date: Sat, 9 Sep 2023 14:06:35 +0200 Subject: [PATCH 1/4] change constants --- config.json | 16 ++++++++-------- src/gmirator/__init__.py | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/config.json b/config.json index d5a01bb..28bd070 100644 --- a/config.json +++ b/config.json @@ -1,11 +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" + "dir_assets" : "path/to/assets", + "dir_gmi_content" : "path/to/content", + "dir_gmi_helper" : "path/to/gmi-helper", + "dir_html_helper" : "path/to/html-helper", + "dir_html_out" : "path/to/web", + "rem_gmi" : "remote_server:path/to/gmi", + "rem_html" : "remote_server:path/to/gmi", + "port" : "1312" } diff --git a/src/gmirator/__init__.py b/src/gmirator/__init__.py index 7a67d4a..d466b4a 100644 --- a/src/gmirator/__init__.py +++ b/src/gmirator/__init__.py @@ -7,13 +7,14 @@ 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" +DIR_ASSETS = Path(config["dir_assets"]) +DIR_SOURCE = Path(config["dir_gmi_content"]) +DIR_GMI_HELPER = Path(config["dir_gmi_helper"]) +DIR_HELPER = Path(config["dir_html_helper"]) +DIR_O_HTML = Path(config["dir_html_out"]) -REM_HTML = config["rem_html"] -REM_GMI = config["rem_gmi"] -RPORT = config["port"] +GMI_FOOTER = DIR_GMI_HELPER / "footer.gmi" + +REM_HTML = config["rem_html"] +REM_GMI = config["rem_gmi"] +RPORT = config["port"] From 06bc97ab77c00461eb80db9b630fdce47ac0c5db Mon Sep 17 00:00:00 2001 From: stev Date: Sat, 9 Sep 2023 14:07:11 +0200 Subject: [PATCH 2/4] fix repl_url() which was broken --- src/gmirator/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gmirator/generate.py b/src/gmirator/generate.py index 5ebadde..b56168d 100644 --- a/src/gmirator/generate.py +++ b/src/gmirator/generate.py @@ -156,7 +156,7 @@ def process_inline(line: str): def repl_url(matchobj: re.Match): url, text = matchobj.groupdict().values() - if not re.findall(r'=> (http|gemini)', url): + if not re.findall(r'(http|gemini)', url): url = re.sub(r'gmi$', r'html', url) return f'=> {text if text else url}
\n' From 99288c294a39ed127d22a8236e547f0073694c28 Mon Sep 17 00:00:00 2001 From: stev Date: Sat, 9 Sep 2023 14:07:55 +0200 Subject: [PATCH 3/4] add new tests --- tests/test_generate.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_generate.py b/tests/test_generate.py index a49c6ce..c69ca57 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -1,3 +1,4 @@ +import re from gmirator.generate import ( process_file, process_list, @@ -11,13 +12,26 @@ def test_process_file(): pass def test_process_list(): + test_str = "this is a line outside a list" + assert process_list(test_str, True) == ("\n\n", False) + assert process_list(test_str, False) == (test_str, False) + test_str = "* this is a list item" + assert process_list(test_str, True) == ("
  • this is a list item
  • ", True) + assert process_list(test_str, False) == ("
      \n
    • this is a list item
    • ", True) pass def test_process_inline(): assert process_inline("*Hello* ~~world~~!") == "Hello world!" -def test_repl_url(): - pass +def test_repl_url_external_gmi_url(): + external_url = "=> gemini://domain/gempage.gmi\n" + new_url = re.sub(r'^=> (?P[^ ]*) ?(?P.*)\n', repl_url, external_url) + assert new_url == '=> gemini://domain/gempage.gmi
      \n' + +def test_repl_url_internal_gmi_url(): + external_url = "=> /gempage.gmi title\n" + new_url = re.sub(r'^=> (?P[^ ]*) ?(?P.*)\n', repl_url, external_url) + assert new_url == '=> title
      \n' def test_repl_heading(): pass From e3642177343e1404550f6cc2e57bfdaa45fd89c2 Mon Sep 17 00:00:00 2001 From: stev Date: Sat, 9 Sep 2023 14:08:04 +0200 Subject: [PATCH 4/4] update README --- README.md | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 269deae..4fac3b0 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,19 @@ 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. +For now, this is very rudimentary and things are bound to change... and break from +version to version. + +## Features + +- generates HTML from gemtext +- can synchronise your files with your server using rsync + +## Notes on usage + +Good practice for gemini dictates that we don't use multiple `h1` titles in one page +and for that reason, the last (and therefore the first) `h1` title encountered will +be used as the title of the HTML page. ## TODO @@ -23,12 +34,14 @@ I structure the directory where my content lives. - [ ] 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 ? +- [ ] reorganise the directory where the content is ## My setup + My current folder structure for my capsule+website looks something like this: ``` -my-internet +myinternet ├── assets │ ├── favicon.ico │ └── style.css @@ -37,9 +50,20 @@ my-internet │ │ └── index.gmi │ ├── index.gmi │ └── projects.gmi -├── footer.gmi -├── html-output -└── html-parts - ├── footer-part.html - └── header-part.html +├── gmi-helper +│ └── footer.gmi +├── html-helper +│ ├── footer-part.html +│ └── header-part.html +├── README.md +└── web + ├── favicon.ico + ├── gemlog + │ └── index.html + ├── index.html + ├── projects.html + └── style.css ``` + +This is only meant as a reference if my code isn't clear enough and had too much +implicits