@@ -2,8 +2,10 @@ package main
22
33import (
44 "bytes"
5+ "crypto/md5"
56 "errors"
67 "flag"
8+ "fmt"
79 "html/template"
810 "io"
911 "io/fs"
@@ -12,6 +14,7 @@ import (
1214 "os"
1315 "path/filepath"
1416 "regexp"
17+ "retroblog/parser"
1518 "sort"
1619 "strconv"
1720 "strings"
3336)
3437
3538func init () {
36- flag .StringVar (& srcDir , "src" , "/tmp /apple_notes_export" , "Notes source directory" )
39+ flag .StringVar (& srcDir , "src" , ". /apple_notes_export" , "Notes source directory" )
3740 flag .StringVar (& outDir , "out" , "./public" , "Output directory" )
3841 flag .StringVar (& addr , "addr" , ":8080" , "HTTP listen address" )
3942}
@@ -442,8 +445,11 @@ func transformAttachmentTagsByMeta(body, slug string, meta NoteMeta) string {
442445 // Copied file lives at: out/<category>/<slug>/attachments/...
443446 rel := filepath .ToSlash (filepath .Join (slug , att .Path ))
444447 ext := strings .ToLower (filepath .Ext (att .Path ))
448+ ext_v2 := strings .ToLower (filepath .Ext (att .OriginalFilename ))
445449
446- switch ext {
450+ log .Printf ("Transforming attachment ID %s (%s) ext (%s) to HTML tag" , id , att .Path , ext_v2 )
451+
452+ switch ext_v2 {
447453 case ".jpg" , ".jpeg" , ".png" , ".gif" , ".bmp" , ".webp" , ".svg" :
448454 alt := att .OriginalFilename
449455 if alt == "" {
@@ -457,14 +463,25 @@ func transformAttachmentTagsByMeta(body, slug string, meta NoteMeta) string {
457463</object>`
458464 case ".mp4" , ".webm" , ".ogg" , ".mov" :
459465 return `<video controls style="max-width:100%;">
460- <source src="` + rel + `" type="video/` + strings .TrimPrefix (ext , "." ) + `">
466+ <source src="` + rel + `" type="video/` + strings .TrimPrefix (ext_v2 , "." ) + `">
461467 <a href="` + rel + `">Download video</a>
462468</video>`
463469 case ".mp3" , ".wav" , ".flac" , ".m4a" , ".aac" , ".oga" :
464470 return `<audio controls>
465- <source src="` + rel + `" type="audio/` + strings .TrimPrefix (ext , "." ) + `">
471+ <source src="` + rel + `" type="audio/` + strings .TrimPrefix (ext_v2 , "." ) + `">
466472 <a href="` + rel + `">Download audio</a>
467473</audio>`
474+
475+ case ".nes" :
476+ // Generate unique ID for this NES player instance
477+ // Use a hash of the attachment ID to ensure consistency
478+ uniqueID := fmt .Sprintf ("nes_%x" , md5 .Sum ([]byte (id )))[:12 ]
479+ name := att .OriginalFilename
480+ if name == "" {
481+ name = filepath .Base (att .Path )
482+ }
483+ log .Println ("Embedding NES player for" , name , "with ID" , uniqueID )
484+ return parser .GenerateNESPlayerHTML (uniqueID , rel , htmlEscape (name ), ext )
468485 default :
469486 name := att .OriginalFilename
470487 if name == "" {
0 commit comments