Skip to content

Commit

Permalink
add script (romn) in url path
Browse files Browse the repository at this point in the history
  • Loading branch information
siongui committed Oct 23, 2023
1 parent 582325b commit 09d78c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/tipitaka/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func init() {
// ActionToCanonPath converts action string to canon path in URL.
func ActionToCanonPath(action string) string {
noext := strings.TrimSuffix(action, filepath.Ext(action))
return "/" + strings.Replace(noext, ".", "/", -1) + "/"
// TODO: FIXME: elegant way to support different script and edition.
return "/romn/" + strings.Replace(noext, ".", "/", -1) + "/"
}

// PageType represents the type of the webpage, determined according to path of
Expand Down
32 changes: 16 additions & 16 deletions lib/tipitaka/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

func TestActionToCanonPath(t *testing.T) {
s := ActionToCanonPath("cscd/vin01m.mul2.xml")
if s != "/cscd/vin01m/mul2/" {
if s != "/romn/cscd/vin01m/mul2/" {
t.Error(s)
return
}
Expand All @@ -31,8 +31,8 @@ func TestDeterminePageType(t *testing.T) {
if DeterminePageType("/pali-dictionary/") != NoSuchPage {
t.Error("/pali-dictionary/")
}
if DeterminePageType("/cscd/vin01m/mul2/") != CanonPage {
t.Error("/cscd/vin01m/mul2/")
if DeterminePageType("/romn/cscd/vin01m/mul2/") != CanonPage {
t.Error("/romn/cscd/vin01m/mul2/")
}
if DeterminePageType("/pali-dictionary/cscd/vin01m/mul2/") != NoSuchPage {
t.Error("/pali-dictionary/cscd/vin01m/mul2/")
Expand All @@ -46,8 +46,8 @@ func TestDeterminePageType(t *testing.T) {
if DeterminePageType("/pali-dictionary/") != RootPage {
t.Error("/pali-dictionary/")
}
if DeterminePageType("/pali-dictionary/cscd/vin01m/mul2/") != CanonPage {
t.Error("/pali-dictionary/cscd/vin01m/mul2/")
if DeterminePageType("/pali-dictionary/romn/cscd/vin01m/mul2/") != CanonPage {
t.Error("/pali-dictionary/romn/cscd/vin01m/mul2/")
}
if DeterminePageType("/pali-dictionary/zh_TW/cscd/vin01m/mul2/") != NoSuchPage {
t.Error("/pali-dictionary/zh_TW/cscd/vin01m/mul2/")
Expand All @@ -61,8 +61,8 @@ func TestDeterminePageType(t *testing.T) {
//if DeterminePageType("/pali-dictionary/cscd/vin01m/mul2/") != NoSuchPage {
// t.Error("/pali-dictionary/cscd/vin01m/mul2/")
//}
if DeterminePageType("/pali-dictionary/zh_TW/cscd/vin01m/mul2/") != CanonPage {
t.Error("/pali-dictionary/zh_TW/cscd/vin01m/mul2/")
if DeterminePageType("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/") != CanonPage {
t.Error("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/")
}
if DeterminePageType("/pali-dictionary/zh_TW/abc/cscd/vin01m/mul2/") != NoSuchPage {
t.Error("/pali-dictionary/zh_TW/abc/cscd/vin01m/mul2/")
Expand All @@ -73,40 +73,40 @@ func TestIsValidCanonUrlPath(t *testing.T) {
SetSiteUrl("")
SetCurrentLocale("")

if IsValidCanonUrlPath("/cscd/vin01m/mul2/") != true {
t.Error("/cscd/vin01m/mul2/")
if IsValidCanonUrlPath("/romn/cscd/vin01m/mul2/") != true {
t.Error("/romn/cscd/vin01m/mul2/")
}

if IsValidCanonUrlPath("/abc/cscd/vin01m/mul2/") != false {
t.Error("/abc/cscd/vin01m/mul2/")
}

SetSiteUrl("https://siongui.gitlab.io/pali-dictionary/")
if IsValidCanonUrlPath("/pali-dictionary/cscd/vin01m/mul2/") != true {
t.Error("/pali-dictionary/cscd/vin01m/mul2/")
if IsValidCanonUrlPath("/pali-dictionary/romn/cscd/vin01m/mul2/") != true {
t.Error("/pali-dictionary/romn/cscd/vin01m/mul2/")
}

SetCurrentLocale("zh_TW")
if IsValidCanonUrlPath("/pali-dictionary/zh_TW/cscd/vin01m/mul2/") != true {
t.Error("/pali-dictionary/zh_TW/cscd/vin01m/mul2/")
if IsValidCanonUrlPath("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/") != true {
t.Error("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/")
}
}

func TestActionToUrlPath(t *testing.T) {
SetSiteUrl("")
SetCurrentLocale("")

if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/cscd/vin01m/mul2/" {
if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/romn/cscd/vin01m/mul2/" {
t.Error("cscd/vin01m.mul2.xml")
}

SetSiteUrl("https://siongui.gitlab.io/pali-dictionary/")
if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/pali-dictionary/cscd/vin01m/mul2/" {
if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/pali-dictionary/romn/cscd/vin01m/mul2/" {
t.Error("cscd/vin01m.mul2.xml")
}

SetCurrentLocale("zh_TW")
if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/pali-dictionary/zh_TW/cscd/vin01m/mul2/" {
if ActionToUrlPath("cscd/vin01m.mul2.xml") != "/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/" {
t.Error("cscd/vin01m.mul2.xml")
}
}

0 comments on commit 09d78c2

Please sign in to comment.