diff options
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r-- | ishtar_common/views.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 73c516661..3f060f2e1 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -79,6 +79,7 @@ from ishtar_common.utils import ( dict_to_tuple, put_session_message, get_model_by_slug, + human_date, ) from ishtar_common.widgets import JQueryAutoComplete from ishtar_common import tasks @@ -1215,8 +1216,29 @@ class ChangelogView(IshtarMixin, LoginRequiredMixin, TemplateView): if not current_file: raise Http404() changelog_file = os.path.join(changelog_dir, current_file) + VERSION_RE = re.compile(r"<h2>(.*) - (\d{4})-(\d{2})-(\d{2})</h2>") with open(changelog_file, "r", encoding="utf-8") as changelog: - context["changelog"] = markdown(changelog.read()) + changelog_base = markdown(changelog.read()) + changelog_full = "" + for line in changelog_base.split("\n"): + line = line.strip() + if not line: + continue + # <h2>v4.0.42 - 2023-01-25</h2> + m = VERSION_RE.match(line) + if not m: + changelog_full += line + continue + version, year, month, day = m.groups() + try: + d = datetime.date(int(year), int(month), int(day)) + except ValueError: + changelog_full += line + continue + changelog_full += f"<div id='{version}' class='version'>" + changelog_full += f"<span class='date'>{human_date(d)}</span>" + changelog_full += f"<span class='detail-version'>{version}</span></div>" + context["changelog"] = changelog_full if page_number > 1: context["next"] = page_number - 1 |