Improved breadcrumbs list
This commit is contained in:
1 parent
2b4e1dbc57
commit
ea3eba180b
4 files changed
+100
-36
No files matched your search
@@ -11,12 +11,18 @@ func buildBreadcrumbs(
|
||||
path string,
|
||||
) []Breadcrumb {
|
||||
|
||||
path = cleanSemanticPath(path)
|
||||
path =
|
||||
strings.TrimSpace(path)
|
||||
|
||||
if path == "/" {
|
||||
if path == "" ||
|
||||
path == "/" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
parts :=
|
||||
strings.Split(
|
||||
strings.Trim(path, "/"),
|
||||
@@ -26,14 +32,21 @@ func buildBreadcrumbs(
|
||||
var out []Breadcrumb
|
||||
current := ""
|
||||
|
||||
for _, p := range parts {
|
||||
for _, part := range parts {
|
||||
|
||||
current += "/" + p
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
out = append(out, Breadcrumb{
|
||||
Name: p,
|
||||
Path: current,
|
||||
})
|
||||
current += "/" + part
|
||||
|
||||
out = append(
|
||||
out,
|
||||
Breadcrumb{
|
||||
Name: part,
|
||||
Path: current,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
@@ -82,9 +82,11 @@ func (s *Server) handleHome(
|
||||
ObjectURI: "uuid:" + objectUUID,
|
||||
},
|
||||
),
|
||||
"Title": homePath,
|
||||
"Path": homePath,
|
||||
"ObjectUUID": objectUUID,
|
||||
"IsHome": true,
|
||||
"Title": homePath,
|
||||
"Path": homePath,
|
||||
"Breadcrumbs": buildBreadcrumbs(homePath),
|
||||
"ObjectUUID": objectUUID,
|
||||
"RenderedHTML": template.HTML(
|
||||
rendered,
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
@@ -39,6 +40,9 @@ func (s *Server) handleSemanticRoute(
|
||||
return
|
||||
}
|
||||
|
||||
bs := buildBreadcrumbs(path)
|
||||
log.Printf("breadcrumb debug path=%s bs=%#v", path, bs)
|
||||
|
||||
rendered :=
|
||||
s.expandMacros(
|
||||
latest.Body,
|
||||
@@ -49,9 +53,10 @@ func (s *Server) handleSemanticRoute(
|
||||
w,
|
||||
"page.gohtml",
|
||||
map[string]any{
|
||||
"Title": path,
|
||||
"Path": path,
|
||||
"ObjectUUID": objectUUID,
|
||||
"Title": path,
|
||||
"Path": path,
|
||||
"Breadcrumbs": buildBreadcrumbs(path),
|
||||
"ObjectUUID": objectUUID,
|
||||
"NavItems": resolveNavItems(
|
||||
s.getSystemNavItems(),
|
||||
NavContext{
|
||||
|
||||
+66
-22
@@ -3,48 +3,56 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/o/path:/system/static/css/main.css"
|
||||
>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/o/path:/system/static/css/modes.css"
|
||||
>
|
||||
|
||||
<title>{{ .Name }}</title>
|
||||
<link rel="stylesheet" href="/o/path:/system/static/css/main.css">
|
||||
<link rel="stylesheet" href="/o/path:/system/static/css/modes.css">
|
||||
</head>
|
||||
|
||||
<body class="mode-page">
|
||||
<body class="mode-page {{ if .IsHome }}is-home-page{{ end }}">
|
||||
|
||||
<header class="topbar">
|
||||
|
||||
<div class="brand">
|
||||
<a href="/">{{ .WikiName }}</a>
|
||||
<a href="/">{{ .WikiName }}</a>
|
||||
</div>
|
||||
|
||||
|
||||
<nav>
|
||||
{{ range .NavItems }}
|
||||
<a href="{{ .ResolvedHref }}">{{ .Label }}</a>
|
||||
{{ end }}
|
||||
</nav>
|
||||
|
||||
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
|
||||
<section class="card">
|
||||
<section>
|
||||
|
||||
<div class="path-label">
|
||||
{{ .Path }}
|
||||
</div>
|
||||
{{ if ne .Path "/" }}
|
||||
|
||||
<!-- DEBUG Breadcrumbs: {{ printf "%#v" .Breadcrumbs }} -->
|
||||
<nav class="breadcrumbs">
|
||||
|
||||
<a href="/">
|
||||
/
|
||||
</a>
|
||||
|
||||
{{ range .Breadcrumbs }}
|
||||
|
||||
<span class="breadcrumb-sep">
|
||||
/
|
||||
</span>
|
||||
|
||||
<a href="{{ .Path }}">
|
||||
{{ .Name }}
|
||||
</a>
|
||||
|
||||
{{ end }}
|
||||
|
||||
</nav>
|
||||
|
||||
{{ end }}
|
||||
|
||||
<article class="page-html">
|
||||
{{ .RenderedHTML }}
|
||||
@@ -56,6 +64,32 @@
|
||||
|
||||
<style>
|
||||
|
||||
.breadcrumbs {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin-bottom: 1rem;
|
||||
font-family:
|
||||
"JetBrains Mono",
|
||||
monospace;
|
||||
font-size: 0.86rem;
|
||||
}
|
||||
|
||||
.breadcrumbs a {
|
||||
text-decoration: none;
|
||||
color: #9cc8ff;
|
||||
}
|
||||
|
||||
.breadcrumbs a:hover {
|
||||
color: #d6e9ff;
|
||||
text-shadow:
|
||||
0 0 0.35rem rgba(120,180,255,0.28);
|
||||
}
|
||||
|
||||
.breadcrumb-sep {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.children-list ul {
|
||||
margin: 0;
|
||||
padding-left: 1.2rem;
|
||||
@@ -65,6 +99,16 @@
|
||||
margin: 0.15rem 0;
|
||||
}
|
||||
|
||||
|
||||
.is-root-page .breadcrumbs {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
.is-home-page .breadcrumbs {
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user