Skip to content

Commit

Permalink
add paliTextPath in the return of IsValidPaliTextUrlPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
siongui committed Oct 25, 2023
1 parent 5c4c36e commit 783375e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 8 additions & 8 deletions lib/tipitaka/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ActionToPaliTextPath(action string) string {
return "/romn/" + strings.Replace(noext, ".", "/", -1) + "/"
}

// GetAllPaliTextPath returns all canon paths according to given script.
// GetAllPaliTextPath returns all pali text paths according to given script.
// TODO FIXME: add *edition* parameter in the future.
func GetAllPaliTextPath(script string) []string {
// FIXME TODO: script param is not respected right now. return only romn
Expand Down Expand Up @@ -97,20 +97,20 @@ func DeterminePageType(urlpath string) PageType {
if urlpath == "/" {
return RootPage
}
if IsValidPaliTextUrlPath(urlpath) {
if ok, _ := IsValidPaliTextUrlPath(urlpath); ok {
return PaliTextPage
}

return NoSuchPage
}

// IsValidPaliTextUrlPath will return true if the path of the url is a possible
// canon page.
func IsValidPaliTextUrlPath(urlpath string) bool {
urlpath, _ = dictionary.GetNormalizedUrlPath(urlpath)
// IsValidPaliTextUrlPath will return both true and pali text path if the path
// of the url is a possible pali text page.
func IsValidPaliTextUrlPath(urlpath string) (ok bool, paliTextPath string) {
paliTextPath, _ = dictionary.GetNormalizedUrlPath(urlpath)

_, ok := paliTextPathToActionMap[urlpath]
return ok
_, ok = paliTextPathToActionMap[paliTextPath]
return
}

// ActionToUrlPath converts action string to url path.
Expand Down
11 changes: 7 additions & 4 deletions lib/tipitaka/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,24 @@ func TestIsValidPaliTextUrlPath(t *testing.T) {
SetSiteUrl("")
SetCurrentLocale("")

if IsValidPaliTextUrlPath("/romn/cscd/vin01m/mul2/") != true {
ok, paliTextPath := IsValidPaliTextUrlPath("/romn/cscd/vin01m/mul2/")
if !(ok == true && paliTextPath == "/romn/cscd/vin01m/mul2/") {
t.Error("/romn/cscd/vin01m/mul2/")
}

if IsValidPaliTextUrlPath("/abc/cscd/vin01m/mul2/") != false {
if ok, _ := IsValidPaliTextUrlPath("/abc/cscd/vin01m/mul2/"); ok != false {
t.Error("/abc/cscd/vin01m/mul2/")
}

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

SetCurrentLocale("zh_TW")
if IsValidPaliTextUrlPath("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/") != true {
ok, paliTextPath = IsValidPaliTextUrlPath("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/")
if !(ok == true && paliTextPath == "/romn/cscd/vin01m/mul2/") {
t.Error("/pali-dictionary/zh_TW/romn/cscd/vin01m/mul2/")
}
}
Expand Down

0 comments on commit 783375e

Please sign in to comment.