forked from tangled.org/core
Monorepo for Tangled

appview: pages: fix fragments glob

Changed files
+108 -81
appview
pages
templates
repo
issues
fragments
+47 -31
appview/pages/pages.go
··· 36 36 t map[string]*template.Template 37 37 } 38 38 39 - 40 - 41 39 func NewPages() *Pages { 42 40 templates := make(map[string]*template.Template) 43 - fragmentPaths := []string{} 44 41 42 + var fragmentPaths []string 45 43 // First, collect all fragment paths 46 44 err := fs.WalkDir(Files, "templates", func(path string, d fs.DirEntry, err error) error { 47 45 if err != nil { 48 46 return err 49 47 } 50 48 51 - if !d.IsDir() && strings.HasSuffix(path, ".html") && strings.Contains(path, "fragments/") { 52 - fragmentPaths = append(fragmentPaths, path) 49 + if d.IsDir() { 50 + return nil 53 51 } 54 - return nil 55 - }) 56 - if err != nil { 57 - log.Fatalf("walking template dir for fragments: %v", err) 58 - } 52 + 53 + if !strings.HasSuffix(path, ".html") { 54 + return nil 55 + } 56 + 57 + if !strings.Contains(path, "fragments/") { 58 + return nil 59 + } 59 60 60 - // Load all fragments first 61 - for _, path := range fragmentPaths { 62 61 name := strings.TrimPrefix(path, "templates/") 63 62 name = strings.TrimSuffix(name, ".html") 64 63 ··· 70 69 } 71 70 72 71 templates[name] = tmpl 72 + fragmentPaths = append(fragmentPaths, path) 73 73 log.Printf("loaded fragment: %s", name) 74 + return nil 75 + }) 76 + if err != nil { 77 + log.Fatalf("walking template dir for fragments: %v", err) 74 78 } 75 79 76 80 // Then walk through and setup the rest of the templates ··· 79 83 return err 80 84 } 81 85 82 - if !d.IsDir() && strings.HasSuffix(path, ".html") { 83 - name := strings.TrimPrefix(path, "templates/") 84 - name = strings.TrimSuffix(name, ".html") 86 + if d.IsDir() { 87 + return nil 88 + } 85 89 86 - // Skip fragments as they've already been loaded 87 - if strings.Contains(path, "fragments/") { 88 - return nil 89 - } 90 + if !strings.HasSuffix(path, "html") { 91 + return nil 92 + } 90 93 91 - // Load layouts and main templates 92 - if !strings.HasPrefix(path, "templates/layouts/") { 93 - // Add the page template on top of the base 94 - tmpl, err := template.New(name). 95 - Funcs(funcMap()). 96 - ParseFS(Files, "templates/layouts/*.html", "templates/**/fragments/*.html", path) 97 - if err != nil { 98 - return fmt.Errorf("setting up template: %w", err) 99 - } 94 + // Skip fragments as they've already been loaded 95 + if strings.Contains(path, "fragments/") { 96 + return nil 97 + } 98 + 99 + // Skip layouts 100 + if strings.Contains(path, "layouts/") { 101 + return nil 102 + } 103 + 104 + name := strings.TrimPrefix(path, "templates/") 105 + name = strings.TrimSuffix(name, ".html") 100 106 101 - templates[name] = tmpl 102 - log.Printf("loaded template: %s", name) 103 - } 107 + // Add the page template on top of the base 108 + allPaths := []string{} 109 + allPaths = append(allPaths, "templates/layouts/*.html") 110 + allPaths = append(allPaths, fragmentPaths...) 111 + allPaths = append(allPaths, path) 112 + tmpl, err := template.New(name). 113 + Funcs(funcMap()). 114 + ParseFS(Files, allPaths...) 115 + if err != nil { 116 + return fmt.Errorf("setting up template: %w", err) 104 117 } 118 + 119 + templates[name] = tmpl 120 + log.Printf("loaded template: %s", name) 105 121 return nil 106 122 }) 107 123 if err != nil {
+1 -3
appview/pages/templates/repo/index.html
··· 176 176 <a 177 177 href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}" 178 178 class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 179 - >{{ slice .Hash.String 0 8 }}</a 180 - > 181 - </span> 179 + >{{ slice .Hash.String 0 8 }}</a></span> 182 180 <span 183 181 class="mx-2 before:content-['·'] before:select-none" 184 182 ></span>
+2 -2
appview/pages/templates/repo/issues/fragments/issueComment.html
··· 1 1 {{ define "repo/issues/fragments/issueComment" }} 2 2 {{ with .Comment }} 3 3 <div id="comment-container-{{.CommentId}}"> 4 - <div class="flex items-center gap-2 mb-2 text-gray-500 text-sm"> 4 + <div class="flex items-center gap-2 mb-2 text-gray-500 dark:text-gray-400 text-sm"> 5 5 {{ $owner := index $.DidHandleMap .OwnerDid }} 6 6 <a href="/{{ $owner }}" class="no-underline hover:underline">{{ $owner }}</a> 7 7 8 8 <span class="before:content-['·']"></span> 9 9 <a 10 10 href="#{{ .CommentId }}" 11 - class="text-gray-500 hover:text-gray-500 hover:underline no-underline" 11 + class="text-gray-500 dark:text-gray-400 hover:text-gray-500 dark:hover:text-gray-400 hover:underline no-underline" 12 12 id="{{ .CommentId }}"> 13 13 {{ if .Deleted }} 14 14 deleted {{ .Deleted | timeFmt }}
+58 -45
tailwind.config.js
··· 2 2 const colors = require("tailwindcss/colors"); 3 3 4 4 module.exports = { 5 - content: ["./appview/pages/templates/**/*.html", "./appview/pages/chroma.go"], 6 - darkMode: "media", 7 - theme: { 8 - container: { 9 - padding: "2rem", 10 - center: true, 11 - screens: { 12 - sm: "500px", 13 - md: "600px", 14 - lg: "800px", 15 - xl: "1000px", 16 - "2xl": "1200px", 17 - }, 18 - }, 19 - extend: { 20 - fontFamily: { 21 - sans: ["InterVariable", "system-ui", "sans-serif", "ui-sans-serif"], 22 - mono: [ 23 - "IBMPlexMono", 24 - "ui-monospace", 25 - "SFMono-Regular", 26 - "Menlo", 27 - "Monaco", 28 - "Consolas", 29 - "Liberation Mono", 30 - "Courier New", 31 - "monospace", 32 - ], 33 - }, 34 - typography: { 35 - DEFAULT: { 36 - css: { 37 - maxWidth: "none", 38 - pre: { 39 - backgroundColor: colors.gray[100], 40 - color: colors.black, 41 - "@apply dark:bg-gray-900 dark:text-gray-300 dark:border-gray-700 dark:border": 42 - {}, 43 - }, 44 - }, 45 - }, 46 - }, 47 - }, 48 - }, 49 - plugins: [require("@tailwindcss/typography")], 5 + content: ["./appview/pages/templates/**/*.html", "./appview/pages/chroma.go"], 6 + darkMode: "media", 7 + theme: { 8 + container: { 9 + padding: "2rem", 10 + center: true, 11 + screens: { 12 + sm: "500px", 13 + md: "600px", 14 + lg: "800px", 15 + xl: "1000px", 16 + "2xl": "1200px", 17 + }, 18 + }, 19 + extend: { 20 + fontFamily: { 21 + sans: ["InterVariable", "system-ui", "sans-serif", "ui-sans-serif"], 22 + mono: [ 23 + "IBMPlexMono", 24 + "ui-monospace", 25 + "SFMono-Regular", 26 + "Menlo", 27 + "Monaco", 28 + "Consolas", 29 + "Liberation Mono", 30 + "Courier New", 31 + "monospace", 32 + ], 33 + }, 34 + typography: { 35 + DEFAULT: { 36 + css: { 37 + maxWidth: "none", 38 + pre: { 39 + backgroundColor: colors.gray[100], 40 + color: colors.black, 41 + "@apply font-normal text-black bg-gray-100 dark:bg-gray-900 dark:text-gray-300 dark:border-gray-700 dark:border": {}, 42 + }, 43 + code: { 44 + "@apply font-normal font-mono p-1 rounded text-black bg-gray-100 dark:bg-gray-900 dark:text-gray-300 dark:border-gray-700": {}, 45 + }, 46 + "code::before": { 47 + content: '""', 48 + "padding-left": "0.25rem" 49 + }, 50 + "code::after": { 51 + content: '""', 52 + "padding-right": "0.25rem" 53 + }, 54 + blockquote: { 55 + quotes: "none", 56 + }, 57 + }, 58 + }, 59 + }, 60 + }, 61 + }, 62 + plugins: [require("@tailwindcss/typography")], 50 63 };