Repos / s4g / 1bf0661102
commit 1bf0661102e74b3843eccab00920d1872c61d525
Author: Nhân <hi@imnhan.com>
Date: Sun Jul 9 17:29:02 2023 +0700
sort manifest content; start djot.js on demand
diff --git a/djot/djot.go b/djot/djot.go
index 174e50e..d412c2f 100644
--- a/djot/djot.go
+++ b/djot/djot.go
@@ -1,3 +1,4 @@
+// Must run djot.StartService() before using it.
package djot
import (
@@ -26,12 +27,7 @@ type djotJSProc struct {
var service djotJSProc
-func init() {
- service = StartService()
- fmt.Println("Started djot.js service")
-}
-
-func StartService() djotJSProc {
+func StartService() {
cmd := exec.Command("node", "-e", djotFullScript)
stdin, err := cmd.StdinPipe()
@@ -64,7 +60,7 @@ func StartService() djotJSProc {
panic(err)
}
- return djotJSProc{cmd: cmd, writer: writer, scanner: scanner}
+ service = djotJSProc{cmd: cmd, writer: writer, scanner: scanner}
}
func splitAtDelimiter(data []byte, atEOF bool) (advance int, token []byte, err error) {
diff --git a/main.go b/main.go
index f3f1685..c4f9c04 100644
--- a/main.go
+++ b/main.go
@@ -40,6 +40,9 @@ func main() {
return
}
+ djot.StartService()
+ fmt.Println("Started djot.js service")
+
absolutePath, err := filepath.Abs(folder)
if err != nil {
panic(err)
diff --git a/manifest.go b/manifest.go
index 8e0f249..42c23f7 100644
--- a/manifest.go
+++ b/manifest.go
@@ -3,6 +3,8 @@
import (
"bufio"
"fmt"
+ "sort"
+ "strings"
"go.imnhan.com/webmaker2000/writablefs"
)
@@ -11,13 +13,12 @@
// Write list of files generated by webmaker2000
func WriteManifest(fsys writablefs.FS, files map[string]bool) {
- content := ""
-
+ lines := make([]string, 0, len(files))
for path := range files {
- content += path + "\n"
+ lines = append(lines, path)
}
-
- fsys.WriteFile(ManifestPath, []byte(content))
+ sort.Strings(lines)
+ fsys.WriteFile(ManifestPath, []byte(strings.Join(lines, "\n")))
}
// Read list of old generated files from the manifest file,
diff --git a/www/manifest.txt b/www/manifest.txt
index c86a93d..73c6c86 100644
--- a/www/manifest.txt
+++ b/www/manifest.txt
@@ -1,5 +1,5 @@
-mfws.html
-hello/index.html
about/index.html
-index.html
feed.xml
+hello/index.html
+index.html
+mfws.html
\ No newline at end of file