this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2 from mariuskimmina/fix-filenames

use sanitized leaflet title as filename

authored by

Marius Kimmina and committed by
GitHub
4ab4ecbf 62abf0ca

+19 -2
+12 -1
cmd/leaflet-hugo-sync/main.go
··· 20 20 return parts[len(parts)-1] 21 21 } 22 22 23 + func sanitizeTitle(title string) string { 24 + // Replace spaces with underscores and remove/replace unsafe characters 25 + s := strings.ReplaceAll(title, " ", "_") 26 + s = strings.ReplaceAll(s, "/", "_") 27 + s = strings.ReplaceAll(s, "\\", "_") 28 + s = strings.ReplaceAll(s, ":", "_") 29 + return s 30 + } 31 + 23 32 func main() { 24 33 configPath := flag.String("config", ".leaflet-sync.yaml", "Path to config file") 25 34 flag.Parse() ··· 141 150 finalContent = strings.ReplaceAll(finalContent, imgRef.Blob.Ref.Link, localPath) 142 151 } 143 152 144 - // Slug generation 153 + // Generate filename from title and slug from URI 145 154 slug := lastPathPart(rec.Uri) 155 + filename := sanitizeTitle(doc.Title) 146 156 147 157 // Construct original URL 148 158 originalURL := fmt.Sprintf("https://leaflet.pub/%s", slug) ··· 151 161 Title: doc.Title, 152 162 CreatedAt: doc.PublishedAt, 153 163 Slug: slug, 164 + Filename: filename, 154 165 Handle: cfg.Source.Handle, 155 166 OriginalURL: originalURL, 156 167 Content: finalContent,
+7 -1
internal/generator/hugo.go
··· 17 17 Title string 18 18 CreatedAt string 19 19 Slug string 20 + Filename string 20 21 Handle string 21 22 OriginalURL string 22 23 Content string ··· 59 60 return err 60 61 } 61 62 62 - fileName := data.Slug + ".md" 63 + // Use Filename if provided, otherwise fall back to Slug 64 + filename := data.Filename 65 + if filename == "" { 66 + filename = data.Slug 67 + } 68 + fileName := filename + ".md" 63 69 filePath := filepath.Join(g.Cfg.Output.PostsDir, fileName) 64 70 65 71 fullContent := bufFM.String() + "\n" + bufContent.String()