Add conflict resolution diff UI and app branding
This commit is contained in:
@@ -53,7 +53,16 @@ func NewRenderer() *Renderer {
|
||||
}
|
||||
|
||||
func (r *Renderer) Render(content []byte) (Result, error) {
|
||||
title := extractTitle(string(content))
|
||||
title, titleFromHeading := extractTitle(string(content), "")
|
||||
return r.renderWithTitle(content, title, titleFromHeading)
|
||||
}
|
||||
|
||||
func (r *Renderer) RenderPath(content []byte, path string) (Result, error) {
|
||||
title, titleFromHeading := extractTitle(string(content), path)
|
||||
return r.renderWithTitle(content, title, titleFromHeading)
|
||||
}
|
||||
|
||||
func (r *Renderer) renderWithTitle(content []byte, title string, titleFromHeading bool) (Result, error) {
|
||||
tags := extractTags(string(content))
|
||||
prepared := preprocess(string(content))
|
||||
|
||||
@@ -62,7 +71,10 @@ func (r *Renderer) Render(content []byte) (Result, error) {
|
||||
return Result{}, fmt.Errorf("render markdown: %w", err)
|
||||
}
|
||||
|
||||
html := firstH1Pattern.ReplaceAllString(output.String(), "")
|
||||
html := output.String()
|
||||
if titleFromHeading {
|
||||
html = firstH1Pattern.ReplaceAllString(html, "")
|
||||
}
|
||||
|
||||
return Result{
|
||||
HTML: template.HTML(html),
|
||||
@@ -123,13 +135,14 @@ func normalizeAdmonition(line string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func extractTitle(content string) string {
|
||||
func extractTitle(content string, path string) (string, bool) {
|
||||
for _, line := range strings.Split(content, "\n") {
|
||||
if strings.HasPrefix(line, "# ") {
|
||||
return strings.TrimSpace(strings.TrimPrefix(line, "# "))
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if strings.HasPrefix(trimmed, "# ") {
|
||||
return strings.TrimSpace(strings.TrimPrefix(trimmed, "# ")), true
|
||||
}
|
||||
}
|
||||
return "Untitled"
|
||||
return titleFromPath(path), false
|
||||
}
|
||||
|
||||
func extractTags(content string) []string {
|
||||
@@ -169,3 +182,35 @@ func slugify(value string) string {
|
||||
}
|
||||
return strings.Trim(builder.String(), "-")
|
||||
}
|
||||
|
||||
func titleFromPath(path string) string {
|
||||
path = strings.Trim(path, "/")
|
||||
path = strings.TrimSuffix(path, ".md")
|
||||
if path == "" {
|
||||
return "Home"
|
||||
}
|
||||
|
||||
base := path
|
||||
if strings.HasSuffix(base, "/index") {
|
||||
base = strings.TrimSuffix(base, "/index")
|
||||
}
|
||||
if base == "index" {
|
||||
return "Home"
|
||||
}
|
||||
if idx := strings.LastIndex(base, "/"); idx >= 0 {
|
||||
base = base[idx+1:]
|
||||
}
|
||||
base = strings.ReplaceAll(base, "-", " ")
|
||||
base = strings.ReplaceAll(base, "_", " ")
|
||||
parts := strings.Fields(base)
|
||||
for i, part := range parts {
|
||||
if part == strings.ToUpper(part) {
|
||||
continue
|
||||
}
|
||||
parts[i] = strings.ToUpper(part[:1]) + strings.ToLower(part[1:])
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return "Home"
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user