2021-01-05 21:05:40 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-01-05 21:05:40 +08:00
|
|
|
|
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-04-12 18:16:45 +08:00
|
|
|
"code.gitea.io/gitea/modules/assetfs"
|
2021-01-05 21:05:40 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
)
|
|
|
|
|
2023-04-12 18:16:45 +08:00
|
|
|
func AssetFS() *assetfs.LayeredFS {
|
|
|
|
return assetfs.Layered(CustomAssets(), BuiltinAssets())
|
2022-08-28 17:43:25 +08:00
|
|
|
}
|
|
|
|
|
2023-04-12 18:16:45 +08:00
|
|
|
func CustomAssets() *assetfs.Layer {
|
|
|
|
return assetfs.Local("custom", setting.CustomPath, "templates")
|
|
|
|
}
|
2021-01-05 21:05:40 +08:00
|
|
|
|
2023-04-12 18:16:45 +08:00
|
|
|
func ListWebTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
|
|
|
|
files, err := assets.ListAllFiles(".", true)
|
2021-01-05 21:05:40 +08:00
|
|
|
if err != nil {
|
2023-04-12 18:16:45 +08:00
|
|
|
return nil, err
|
2021-01-05 21:05:40 +08:00
|
|
|
}
|
2023-04-12 18:16:45 +08:00
|
|
|
return util.SliceRemoveAllFunc(files, func(file string) bool {
|
|
|
|
return strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
|
|
|
|
}), nil
|
2021-01-05 21:05:40 +08:00
|
|
|
}
|
2021-01-26 23:36:53 +08:00
|
|
|
|
2023-04-12 18:16:45 +08:00
|
|
|
func ListMailTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
|
|
|
|
files, err := assets.ListAllFiles(".", true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-08-28 17:43:25 +08:00
|
|
|
}
|
2023-04-12 18:16:45 +08:00
|
|
|
return util.SliceRemoveAllFunc(files, func(file string) bool {
|
|
|
|
return !strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
|
|
|
|
}), nil
|
2021-01-26 23:36:53 +08:00
|
|
|
}
|