Merge pull request #684 from trheyi/main
Fix the bug in the SUI language pack path
This commit is contained in:
commit
eaf1fdc377
7 changed files with 64 additions and 11 deletions
|
|
@ -20,6 +20,38 @@ func TestCompile(t *testing.T) {
|
||||||
assert.Len(t, warnings, 0)
|
assert.Len(t, warnings, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTrans(t *testing.T) {
|
||||||
|
prepare(t)
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
tmpl := testTmpl(t)
|
||||||
|
option := &core.BuildOption{SSR: true, AssetRoot: "/unit-test/assets"}
|
||||||
|
warnings, err := tmpl.Trans(option)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Len(t, warnings, 0)
|
||||||
|
warnings, err = tmpl.Build(option)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Len(t, warnings, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTmpl(t *testing.T) core.ITemplate {
|
||||||
|
sui := core.SUIs["test"]
|
||||||
|
if sui == nil {
|
||||||
|
t.Fatal("SUI test not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := sui.GetTemplate("advanced")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmpl
|
||||||
|
}
|
||||||
|
|
||||||
func testPage(t *testing.T) *core.Page {
|
func testPage(t *testing.T) *core.Page {
|
||||||
|
|
||||||
sui := core.SUIs["test"]
|
sui := core.SUIs["test"]
|
||||||
|
|
@ -159,6 +159,7 @@ func (r *Request) Render() (string, int, error) {
|
||||||
Debug: r.Request.DebugMode(),
|
Debug: r.Request.DebugMode(),
|
||||||
DisableCache: r.Request.DisableCache(),
|
DisableCache: r.Request.DisableCache(),
|
||||||
Route: r.Request.URL.Path,
|
Route: r.Request.URL.Path,
|
||||||
|
Root: c.Root,
|
||||||
Request: true,
|
Request: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +197,8 @@ func (r *Request) MakeCache() (*core.Cache, int, error) {
|
||||||
configText := ""
|
configText := ""
|
||||||
cacheStore := ""
|
cacheStore := ""
|
||||||
cacheTime := 0
|
cacheTime := 0
|
||||||
dateCacheTime := 0
|
dataCacheTime := 0
|
||||||
|
root := ""
|
||||||
|
|
||||||
configSel := doc.Find("script[name=config]")
|
configSel := doc.Find("script[name=config]")
|
||||||
if configSel != nil && configSel.Length() > 0 {
|
if configSel != nil && configSel.Length() > 0 {
|
||||||
|
|
@ -222,7 +224,8 @@ func (r *Request) MakeCache() (*core.Cache, int, error) {
|
||||||
// Cache store
|
// Cache store
|
||||||
cacheStore = conf.CacheStore
|
cacheStore = conf.CacheStore
|
||||||
cacheTime = conf.Cache
|
cacheTime = conf.Cache
|
||||||
dateCacheTime = conf.DataCache
|
dataCacheTime = conf.DataCache
|
||||||
|
root = conf.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
dataText := ""
|
dataText := ""
|
||||||
|
|
@ -253,8 +256,9 @@ func (r *Request) MakeCache() (*core.Cache, int, error) {
|
||||||
GuardRedirect: guardRedirect,
|
GuardRedirect: guardRedirect,
|
||||||
Config: configText,
|
Config: configText,
|
||||||
CacheStore: cacheStore,
|
CacheStore: cacheStore,
|
||||||
|
Root: root,
|
||||||
CacheTime: time.Duration(cacheTime) * time.Second,
|
CacheTime: time.Duration(cacheTime) * time.Second,
|
||||||
DataCacheTime: time.Duration(dateCacheTime) * time.Second,
|
DataCacheTime: time.Duration(dataCacheTime) * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
go core.SetCache(r.File, cache)
|
go core.SetCache(r.File, cache)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ type Cache struct {
|
||||||
Guard string
|
Guard string
|
||||||
GuardRedirect string
|
GuardRedirect string
|
||||||
HTML string
|
HTML string
|
||||||
|
Root string
|
||||||
CacheStore string
|
CacheStore string
|
||||||
CacheTime time.Duration
|
CacheTime time.Duration
|
||||||
DataCacheTime time.Duration
|
DataCacheTime time.Duration
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ func (page *Page) GetConfig() *PageConfig {
|
||||||
page.Config.Mock = &PageMock{Method: "GET"}
|
page.Config.Mock = &PageMock{Method: "GET"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page.Config.Root = page.Root
|
||||||
return page.Config
|
return page.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,6 +70,7 @@ func (page *Page) ExportConfig() string {
|
||||||
"cache_store": page.CacheStore,
|
"cache_store": page.CacheStore,
|
||||||
"cache": page.Config.Cache,
|
"cache": page.Config.Cache,
|
||||||
"data_cache": page.Config.DataCache,
|
"data_cache": page.Config.DataCache,
|
||||||
|
"root": page.Root,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ type ParserOption struct {
|
||||||
Route string `json:"route,omitempty"`
|
Route string `json:"route,omitempty"`
|
||||||
Theme any `json:"theme,omitempty"`
|
Theme any `json:"theme,omitempty"`
|
||||||
Locale any `json:"locale,omitempty"`
|
Locale any `json:"locale,omitempty"`
|
||||||
|
Root string `json:"root,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var keepWords = map[string]bool{
|
var keepWords = map[string]bool{
|
||||||
|
|
@ -128,9 +129,9 @@ func (parser *TemplateParser) Locale() *Locale {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
route := parser.option.Route
|
root := parser.option.Root
|
||||||
|
route := strings.TrimPrefix(parser.option.Route, root)
|
||||||
disableCache := parser.option.Preview || parser.option.Debug || parser.option.Editor || parser.option.DisableCache
|
disableCache := parser.option.Preview || parser.option.Debug || parser.option.Editor || parser.option.DisableCache
|
||||||
|
|
||||||
locales, ok = Locales[name]
|
locales, ok = Locales[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
locales = map[string]*Locale{}
|
locales = map[string]*Locale{}
|
||||||
|
|
@ -141,7 +142,7 @@ func (parser *TemplateParser) Locale() *Locale {
|
||||||
return locale
|
return locale
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join("public", ".locales", name, route+".yml")
|
path := filepath.Join("public", parser.option.Root, ".locales", name, route+".yml")
|
||||||
if exists, err := application.App.Exists(path); !exists {
|
if exists, err := application.App.Exists(path); !exists {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[parser] %s Locale %s", route, err.Error())
|
log.Error("[parser] %s Locale %s", route, err.Error())
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ type Page struct {
|
||||||
SuiID string `json:"-"`
|
SuiID string `json:"-"`
|
||||||
Config *PageConfig `json:"-"`
|
Config *PageConfig `json:"-"`
|
||||||
Path string `json:"-"`
|
Path string `json:"-"`
|
||||||
|
Root string `json:"-"`
|
||||||
Codes SourceCodes `json:"-"`
|
Codes SourceCodes `json:"-"`
|
||||||
Document []byte `json:"-"`
|
Document []byte `json:"-"`
|
||||||
GlobalData []byte `json:"-"`
|
GlobalData []byte `json:"-"`
|
||||||
|
|
@ -259,6 +260,7 @@ type BuildOption struct {
|
||||||
SSR bool `json:"ssr"`
|
SSR bool `json:"ssr"`
|
||||||
CDN bool `json:"cdn"`
|
CDN bool `json:"cdn"`
|
||||||
UpdateAll bool `json:"update_all"`
|
UpdateAll bool `json:"update_all"`
|
||||||
|
PublicRoot string `json:"public_root,omitempty"`
|
||||||
AssetRoot string `json:"asset_root,omitempty"`
|
AssetRoot string `json:"asset_root,omitempty"`
|
||||||
IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"`
|
IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"`
|
||||||
IgnoreDocument bool `json:"ignore_document,omitempty"`
|
IgnoreDocument bool `json:"ignore_document,omitempty"`
|
||||||
|
|
@ -373,6 +375,7 @@ type PageSetting struct {
|
||||||
Guard string `json:"guard,omitempty"`
|
Guard string `json:"guard,omitempty"`
|
||||||
CacheStore string `json:"cache_store,omitempty"`
|
CacheStore string `json:"cache_store,omitempty"`
|
||||||
Cache int `json:"cache,omitempty"`
|
Cache int `json:"cache,omitempty"`
|
||||||
|
Root string `json:"root,omitempty"`
|
||||||
DataCache int `json:"data_cache,omitempty"`
|
DataCache int `json:"data_cache,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
SEO *PageSEO `json:"seo,omitempty"`
|
SEO *PageSEO `json:"seo,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,16 @@ func (tmpl *Template) Build(option *core.BuildOption) ([]string, error) {
|
||||||
|
|
||||||
// loaed pages
|
// loaed pages
|
||||||
tmpl.loaded = map[string]core.IPage{}
|
tmpl.loaded = map[string]core.IPage{}
|
||||||
|
publicRoot, err := tmpl.local.DSL.PublicRoot(option.Data)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Get the public root error: %s. use %s", err.Error(), publicRoot)
|
||||||
|
}
|
||||||
|
option.PublicRoot = publicRoot
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
err := page.Load()
|
err := page.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return warnings, err
|
return warnings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
messages, err := page.Build(ctx, option)
|
messages, err := page.Build(ctx, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return warnings, err
|
return warnings, err
|
||||||
|
|
@ -217,14 +221,20 @@ func (tmpl *Template) SyncAssets(option *core.BuildOption) error {
|
||||||
func (page *Page) Build(globalCtx *core.GlobalBuildContext, option *core.BuildOption) ([]string, error) {
|
func (page *Page) Build(globalCtx *core.GlobalBuildContext, option *core.BuildOption) ([]string, error) {
|
||||||
|
|
||||||
ctx := core.NewBuildContext(globalCtx)
|
ctx := core.NewBuildContext(globalCtx)
|
||||||
if option.AssetRoot == "" {
|
|
||||||
root, err := page.tmpl.local.DSL.PublicRoot(option.Data)
|
var err error = nil
|
||||||
|
root := option.PublicRoot
|
||||||
|
if root == "" {
|
||||||
|
root, err = page.tmpl.local.DSL.PublicRoot(option.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncAssets: Get the public root error: %s. use %s", err.Error(), page.tmpl.local.DSL.Public.Root)
|
log.Error("Get the public root error: %s. use %s", err.Error(), page.tmpl.local.DSL.Public.Root)
|
||||||
root = page.tmpl.local.DSL.Public.Root
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if option.AssetRoot == "" {
|
||||||
option.AssetRoot = filepath.Join(root, "assets")
|
option.AssetRoot = filepath.Join(root, "assets")
|
||||||
}
|
}
|
||||||
|
page.Root = root
|
||||||
|
|
||||||
html, warnings, err := page.Page.Compile(ctx, option)
|
html, warnings, err := page.Page.Compile(ctx, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue