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