From a899379930480a71a20ef06752f595671a2f9280 Mon Sep 17 00:00:00 2001 From: orhtej2 <2871798+orhtej2@users.noreply.github.com> Date: Sat, 1 Feb 2025 19:25:30 +0100 Subject: [PATCH 1/2] Move readmes to subdir + tag them as generated. --- readme_generator/make_readme.py | 35 +++++++++++++++++---- readme_generator/templates/ALL_README.md.j2 | 2 +- readme_generator/templates/README.md.j2 | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/readme_generator/make_readme.py b/readme_generator/make_readme.py index 0c20a343..a2da621a 100755 --- a/readme_generator/make_readme.py +++ b/readme_generator/make_readme.py @@ -60,6 +60,28 @@ def generate_READMEs(app_path: Path, apps_repo_path: Path): ) return + # prepare new home for stuff + if not os.path.exists(app_path / "doc" / "readme"): + os.makedirs(app_path / "doc" / "readme") + + # clean up old entries from root of repo + for entry in app_path.iterdir(): + # only pick files (no folder) on the root of 'screenshots' + if not entry.is_file(): + continue + if entry.name.startswith("README") or entry.name == "ALL_README.md": + os.remove(entry) + + # mark readmes as generated in .gitattributes + gitattributes = "" + if os.path.exists(app_path / ".gitattributes"): + gitattributes = (app_path / ".gitattributes").read_text() + + print(f'Looking {gitattributes.find("*README*.md linguist-generated=true")}') + if gitattributes.find("*README*.md linguist-generated=true") == -1: + gitattributes = "*README*.md linguist-generated=true\n" + gitattributes + (app_path / ".gitattributes").write_text(gitattributes) + poparser = PoFileParser({}) poparser.parse((README_GEN_DIR / "messages.pot").open(encoding="utf-8")) @@ -110,9 +132,9 @@ def generate_READMEs(app_path: Path, apps_repo_path: Path): # ignore '.gitkeep' or any file whose name begins with a dot if entry.name.startswith("."): continue - screenshots.append(str(entry.relative_to(app_path))) + screenshots.append("../screenshots/" + entry.name) - def generate_single_README(lang_suffix: str, lang: str): + def generate_single_README(lang_suffix: str, lang: str, screenshots: List[str], target_path: Path, rel_path: str): env = Environment( loader=FileSystemLoader(README_GEN_DIR / "templates"), extensions=["jinja2.ext.i18n"], @@ -165,13 +187,14 @@ def generate_single_README(lang_suffix: str, lang: str): disclaimer=disclaimer, antifeatures=antifeatures, manifest=manifest, + rel_path=rel_path, ) - (app_path / f"README{lang_suffix}.md").write_text(out) + (target_path / f"README{lang_suffix}.md").write_text(out) - generate_single_README("", "en") + generate_single_README("", "en",screenshots=[f.replace("..", "doc") for f in screenshots], target_path=app_path, rel_path="doc/readme") for lang in fully_translated_langs: - generate_single_README("_" + lang, lang) + generate_single_README("_" + lang, lang, screenshots=screenshots, target_path = app_path / "doc" / "readme", rel_path=".") links_to_other_READMEs = [] for language in fully_translated_langs: @@ -189,7 +212,7 @@ def generate_single_README(lang_suffix: str, lang: str): out: str = env.get_template("ALL_README.md.j2").render( links_to_other_READMEs=links_to_other_READMEs ) - (app_path / "ALL_README.md").write_text(out) + (app_path / "doc" / "readme" / "ALL_README.md").write_text(out) def main(): diff --git a/readme_generator/templates/ALL_README.md.j2 b/readme_generator/templates/ALL_README.md.j2 index 2bdcfe2d..15779885 100644 --- a/readme_generator/templates/ALL_README.md.j2 +++ b/readme_generator/templates/ALL_README.md.j2 @@ -1,6 +1,6 @@ # All available README files by language -- [Read the README in English](README.md) +- [Read the README in English](../../README.md) {% for filename, translated_sentence in links_to_other_READMEs -%} - [{{ translated_sentence }}]({{ filename }}) {% endfor -%} diff --git a/readme_generator/templates/README.md.j2 b/readme_generator/templates/README.md.j2 index d3fd1f16..5661e453 100644 --- a/readme_generator/templates/README.md.j2 +++ b/readme_generator/templates/README.md.j2 @@ -27,7 +27,7 @@ It shall NOT be edited by hand.") }} [![{{ _("Install %(application_name)s with YunoHost")|format(application_name=manifest.name) }}](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app={{manifest.id}}) -*[{{ _("Read this README in other languages.") }}](./ALL_README.md)* +*[{{ _("Read this README in other languages.") }}]({{rel_path}}/ALL_README.md)* > *{{ _("This package allows you to install %(application_name)s quickly and simply on a YunoHost server.")|format(application_name=manifest.name) }}* > *{{ _("If you don't have YunoHost, please consult [the guide](https://yunohost.org/install) to learn how to install it.") }}* From 48bf185fbe799e062cb93d21ddae6226c1604ebc Mon Sep 17 00:00:00 2001 From: orhtej2 <2871798+orhtej2@users.noreply.github.com> Date: Sat, 1 Feb 2025 19:31:08 +0100 Subject: [PATCH 2/2] Update test. --- readme_generator/tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme_generator/tests/README.md b/readme_generator/tests/README.md index 7fa0dc58..68deca9a 100644 --- a/readme_generator/tests/README.md +++ b/readme_generator/tests/README.md @@ -11,7 +11,7 @@ It shall NOT be edited by hand. [![Install GoToSocial with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=gotosocial) -*[Read this README in other languages.](./ALL_README.md)* +*[Read this README in other languages.](doc/readme/ALL_README.md)* > *This package allows you to install GoToSocial quickly and simply on a YunoHost server.* > *If you don't have YunoHost, please consult [the guide](https://yunohost.org/install) to learn how to install it.*