Skip to content

Commit

Permalink
fix abbr formatting in sumangala dict
Browse files Browse the repository at this point in the history
  • Loading branch information
pathnirvana committed Sep 6, 2024
1 parent ad8a524 commit 096ed02
Show file tree
Hide file tree
Showing 6 changed files with 2,774 additions and 2,741 deletions.
2 changes: 1 addition & 1 deletion dev/dicts/dict-input/si-buddhadatta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5017,7 +5017,7 @@
],
[
"අපචිත",
"<r c1>3</r> පදන ලද."
"<r c1>3</r> පුදන ලද."
],
[
"අපචිති",
Expand Down
5,432 changes: 2,716 additions & 2,716 deletions dev/dicts/dict-input/si-sumangala.json

Large diffs are not rendered by default.

42 changes: 26 additions & 16 deletions server/bot-renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
// Compile the regex pattern (do this once, outside the handler)
var (
excludePattern = regexp.MustCompile(`/(fts|dict)/`)
botPathPattern = regexp.MustCompile(`Googlebot|facebookexternalhit`)
treeData map[string]TreeItem
htmlTemplate *template.Template
botPattern = regexp.MustCompile(`(?i)googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0\.|pinterestbot|slackbot|vkshare|w3c_validator|whatsapp|applebot|duckduckbot|msnbot|ia_archiver|facebookplatform|telegram|petalbot|ahrefsbot`)
//botPathPattern = regexp.MustCompile(`Googlebot|facebookexternalhit`)
treeData map[string]TreeItem
htmlTemplate *template.Template
)

type ReplaceRules []struct {
Expand Down Expand Up @@ -125,20 +126,20 @@ func BotRendererMiddleware(c *fiber.Ctx) error {
}

userAgent := c.Get("User-Agent")
//if botPathPattern.MatchString(userAgent) {
data, err := getTemplateData(c.Path())
if err != nil {
fmt.Printf("Error handling bot path %s: %v\n", c.Path(), err)
return c.Next()
}
c.Response().Header.Set("Content-Type", "text/html")
if err := htmlTemplate.Execute(c.Response().BodyWriter(), data); err != nil {
fmt.Printf("Error handling bot path %s: %v\n", c.Path(), err)
return c.Next()
if botPattern.MatchString(userAgent) {
data, err := getTemplateData(c.Path())
if err != nil {
fmt.Printf("Error handling bot path %s: %v\n", c.Path(), err)
return c.Next()
}
c.Response().Header.Set("Content-Type", "text/html")
if err := htmlTemplate.Execute(c.Response().BodyWriter(), data); err != nil {
fmt.Printf("Error handling bot path %s: %v\n", c.Path(), err)
return c.Next()
}
fmt.Printf("Bot render for %s, path %s.\n", userAgent, c.Path())
return nil // Indicate successful handling
}
fmt.Printf("Bot render for %s, path %s.\n", userAgent, c.Path())
return nil // Indicate successful handling
//}

return c.Next()
}
Expand Down Expand Up @@ -197,7 +198,15 @@ type Entry struct {
NoAudio bool `json:"noAudio,omitempty"` // 'omitempty' handles optional fields
}

var ( // cache the most recent file to reuse - not sure if this would be helpful
prevDocument *Document
prevTextFilename string
)

func loadTextFile(filename string) (*Document, error) {
if filename == prevTextFilename {
return prevDocument, nil
}
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
Expand All @@ -206,6 +215,7 @@ func loadTextFile(filename string) (*Document, error) {
if err := json.Unmarshal(data, &doc); err != nil {
return nil, err
}
prevDocument, prevTextFilename = &doc, filename
return &doc, nil
}

Expand Down
6 changes: 3 additions & 3 deletions server/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export CGO_ENABLED=1

# Platforms and architectures to build for
PLATFORMS=(
#"linux/amd64/linux_intel/x86_64-unknown-linux-gnu-gcc"
"linux/amd64/linux_intel/x86_64-unknown-linux-gnu-gcc"
####"linux/arm64/linux_arm"
#"darwin/amd64/macos_intel/"
#"darwin/arm64/macos_m1m2/"
"windows/amd64/windows_intel/x86_64-w64-mingw32-gcc"
#"windows/amd64/windows_intel/x86_64-w64-mingw32-gcc"
####"windows/arm64/windows_arm/"
"windows/386/windows_32bit/i686-w64-mingw32-gcc" # Windows 32-bit
#"windows/386/windows_32bit/i686-w64-mingw32-gcc" # Windows 32-bit
)

# Iterate over each platform
Expand Down
9 changes: 4 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (

"github.com/fatih/color"
"github.com/gofiber/fiber/v2"

//"github.com/gofiber/fiber/v2/middleware/compress" // Import compress middleware for gzip
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
"github.com/skratchdot/open-golang/open"
Expand Down Expand Up @@ -55,9 +54,9 @@ func main() {
app := fiber.New(fiber.Config{AppName: APPNAME, DisableStartupMessage: true})

// Use gzip compression middleware
//app.Use(compress.New(compress.Config{
// Level: compress.LevelBestSpeed, // Adjust compression level as needed
//}))
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // Adjust compression level as needed
}))

initBotRendererMiddleware()
// serve pre-rendered pages to google/fb bots
Expand Down
24 changes: 24 additions & 0 deletions server/tipitaka_lk.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Systemd conf file to run the Go binary in production
# Should be located in /etc/systemd/system/tipitaka_lk.service

[Unit]
Description=Tipitaka.lk Go server
After=network.target

[Service]
Type=simple
User=janaka

WorkingDirectory=/home/janaka/www/tipitaka.lk
ExecStart=/home/janaka/www/tipitaka.lk/tipitaka_lk_linux_intel -no-open
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

# Start Service
# sudo systemctl start tipitaka_lk.service

# View Logs
# journalctl -u tipitaka_lk.service

0 comments on commit 096ed02

Please sign in to comment.