diff options
author | Alan Pearce | 2024-06-21 13:02:08 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-21 15:33:38 +0200 |
commit | fc5fd2edd9b8282497e33a18300eab694d8a89c6 (patch) | |
tree | 18af097c037ef781cc8f6148d7c1ba37e10877c1 /internal/components/packageDetail.templ | |
parent | cac323d9ae70f55a43fd99b73e60cf614be11797 (diff) | |
download | searchix-fc5fd2edd9b8282497e33a18300eab694d8a89c6.tar.lz searchix-fc5fd2edd9b8282497e33a18300eab694d8a89c6.tar.zst searchix-fc5fd2edd9b8282497e33a18300eab694d8a89c6.zip |
refactor: switch to templ for HTML templates
Diffstat (limited to 'internal/components/packageDetail.templ')
-rw-r--r-- | internal/components/packageDetail.templ | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/internal/components/packageDetail.templ b/internal/components/packageDetail.templ new file mode 100644 index 0000000..7b4a5cb --- /dev/null +++ b/internal/components/packageDetail.templ @@ -0,0 +1,99 @@ +package components + +import ( + "searchix/internal/nix" +) + +func licenseName(l nix.License) string { + if l.FullName != "" { + return l.FullName + } else { + return l.Name + } +} + +templ PackageDetail(pkg nix.Package) { + <h2> + if pkg.Broken { + <del>{ pkg.Attribute }</del> + } else { + { pkg.Attribute } + } + </h2> + if pkg.LongDescription != "" { + @markdown(pkg.LongDescription) + } else { + <p>{ pkg.Description }</p> + } + <dl> + if pkg.MainProgram != "" { + <dt>Main Program</dt> + <dd> + <code>{ pkg.MainProgram }</code> + </dd> + } + if len(pkg.Homepages) > 0 { + <dt>Homepage</dt> + <dd> + <ul> + for _, u := range pkg.Homepages { + <li> + <a href={ templ.SafeURL(u) }>{ u }</a> + </li> + } + </ul> + </dd> + } + if pkg.Version != "" { + <dt>Version</dt> + <dd>{ pkg.Version }</dd> + } + if len(pkg.Licenses) > 0 { + <dt>License</dt> + <dd> + <ul> + for _, l := range pkg.Licenses { + <li> + if l.URL != "" { + <a href={ templ.SafeURL(l.URL) }>{ licenseName(l) }</a> + } else { + { licenseName(l) } + } + if l.AppendixURL != "" { + <a href={ templ.SafeURL(l.AppendixURL) }>Appendix</a> + } + </li> + } + </ul> + </dd> + } + if len(pkg.Maintainers) > 0 { + <dt>Maintainers</dt> + <dd> + <ul> + for _, m := range pkg.Maintainers { + <li> + if m.Github != "" { + <a href={ joinPath("https://github.com", m.Github) }>{ m.Name }</a> + } else { + { m.Name } + } + </li> + } + </ul> + </dd> + } + if pkg.Definition != "" { + <dt>Defined</dt> + <dd> + <a href={ templ.SafeURL(pkg.Definition) }>Source</a> + </dd> + } + </dl> +} + +templ PackageDetailPage(tdata TemplateData, pkg nix.Package) { + @Page(tdata) { + @PackageDetail(pkg) + } +} |