From ca8524b79b446dd24cde4878428f50fb71981753 Mon Sep 17 00:00:00 2001 From: tassa-yoniso-manasi-karoto Date: Sat, 7 Sep 2024 16:30:03 +0700 Subject: [PATCH] fix built-in index.html provider --- README.md | 4 ++++ main.go | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2338b58..58f7227 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,13 @@ Download the [lastest release](https://github.com/tassa-yoniso-manasi-karoto/pal 1. Run binary from CLI 2. Open http://localhost:8080/ in your browser +Rare thai vowels are not currently supported by the library (ฤ ฤๅ ฦ ฦๅ) +
ดาวน์โหลดรุ่นล่าสุดได้[ที่นี่](https://github.com/tassa-yoniso-manasi-karoto/pali-transliteration-webui/releases) 1. รันไฟล์ไบนารีจาก CLI 2. เปิด http://localhost:8080/ ในเบราว์เซอร์ของคุณ + +สระไทยที่พบได้น้อยยังไม่รองรับในไลบรารีนี้ในขณะนี้ (ฤ ฤๅ ฦ ฦๅ) \ No newline at end of file diff --git a/main.go b/main.go index 05c1a90..6c8d1b7 100644 --- a/main.go +++ b/main.go @@ -157,13 +157,16 @@ func processTextHandler(w http.ResponseWriter, r *http.Request) { } func indexHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - var tmpl *template.Template exeDir, err := os.Executable() if err != nil { - tmpl, err = template.ParseFiles(index) + log.Error().Err(err).Msg("Error getting executable path") + } + templatePath := filepath.Join(filepath.Dir(exeDir), "index.html") + tmpl := template.New("index") + if _, err := os.Stat(templatePath); os.IsNotExist(err) { log.Info().Msg("Serving built-in index.html") + tmpl, err = tmpl.Parse(index) } else { - templatePath := filepath.Join(filepath.Dir(exeDir), "index.html") log.Info().Msgf("Serving index.html from: %s", templatePath) tmpl, err = template.ParseFiles(templatePath) }