improved template variables for working with ForgeRoot

This commit is contained in:
pho4cexa 2023-01-08 09:27:39 -08:00
parent 838489079e
commit 0eece2a92e
2 changed files with 14 additions and 9 deletions

View file

@ -23,8 +23,10 @@
</head>
<body>
<h1>git.example.com</h1>
<h2>{{ repository_name }}</h2>
<p>clone url: git://git.example.com{{ forge_url_path }}{{ repository_path }}</p>
<h2>{{ repository_path_parent }}
{% if repository_path_parent %} / {% endif %}
{{ repository_name }}</h2>
<p>clone url: git://git.example.com/{{ repository_path }}</p>
<nav>
{% if readme_file %}
<a href="{{ relative_root }}{{ readme_file }}.html">about</a>

View file

@ -308,15 +308,17 @@
(let* ((version-ident "$Id$")
(source-files-list (git-repository->paths-list))
(forge-root (string-append (string-chomp (or (config "forgeroot") "") "/") "/"))
;; should begin and end with "/"
(forge-url-path (string-append (string-chomp (or (config "forgeurlpath") "") "/") "/"))
(repository-path (or (config "path")
(and (not (equal? forge-root "/"))
(string-prefix? forge-root html-repo-path)
(string-drop html-repo-path (string-length forge-root)))
(pathname-strip-directory html-repo-path)))
(template-alist
`(;; variables provided to template at all times. beware: ersatz
;; templates break if you attempt to use a variable with a hyphen.
;; the list of all files in the git repo
(source_files_list . ,source-files-list)
(forge_url_path . ,forge-url-path)
;; the description of the repo, taken from: env, config, cgit-like
;; description file
(repository_description . ,(or (config "description")
@ -330,10 +332,11 @@
(string-chomp ".git")
(pathname-strip-directory))))
;; the path from the forge root to the repository
(repository_path . ,(or (config "path")
(if (string-prefix? forge-root html-repo-path)
(string-drop html-repo-path (string-length forge-root))
(pathname-strip-directory html-repo-path))))
(repository_path . ,repository-path)
;; the repository_path with the last path element removed
(repository_path_parent . ,(or (pathname-directory repository-path) ""))
;; the repository_path_parent as a list of path components
(repository_ancestors . ,(or (string-split (or (pathname-directory repository-path) "") "/") '()))
;; the first README file found among these, if any.
(readme_file . ,(find (cut member <> source-files-list)
'("README.md" "README" "README.txt")))