diff --git a/cmd/addContent.go b/cmd/addContent.go index 81bc041c..c758c6a7 100644 --- a/cmd/addContent.go +++ b/cmd/addContent.go @@ -24,6 +24,7 @@ import ( "github.com/sveltinio/sveltin/internal/composer" sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/markup" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" ) @@ -111,7 +112,7 @@ func init() { //============================================================================= -func promptContentName(fs afero.Fs, inputs []string, isSample bool, c *config.SveltinConfig) (*config.TemplateData, error) { +func promptContentName(fs afero.Fs, inputs []string, isSample bool, c *config.SveltinConfig) (*tpltypes.ContentData, error) { contentType := Blank if isSample { contentType = Sample @@ -133,7 +134,7 @@ func promptContentName(fs afero.Fs, inputs []string, isSample bool, c *config.Sv return nil, err } - return &config.TemplateData{ + return &tpltypes.ContentData{ Name: utils.ToSlug(contentName), Type: contentType, Resource: contentResource, @@ -148,7 +149,7 @@ func promptContentName(fs afero.Fs, inputs []string, isSample bool, c *config.Sv return nil, err } - return &config.TemplateData{ + return &tpltypes.ContentData{ Name: utils.ToSlug(contentName), Type: contentType, Resource: contentResource, @@ -176,7 +177,7 @@ func promptResourceList(fs afero.Fs, c *config.SveltinConfig) (string, error) { //============================================================================= -func makeContentFolderStructure(folderName string, contentData *config.TemplateData) (*composer.Folder, error) { +func makeContentFolderStructure(folderName string, contentData *tpltypes.ContentData) (*composer.Folder, error) { switch folderName { case ContentFolder: return createContentLocalFolder(contentData), nil @@ -191,28 +192,22 @@ func makeContentFolderStructure(folderName string, contentData *config.TemplateD //============================================================================= -func createContentLocalFolder(contentData *config.TemplateData) *composer.Folder { +func createContentLocalFolder(contentData *tpltypes.ContentData) *composer.Folder { // GET FOLDER: content contentFolder := cfg.fsManager.GetFolder(ContentFolder) // NEW FOLDER content// - resourceContentFolder := cfg.fsManager.NewResourceContentFolder(contentData.Name, contentData.Resource) + resourceContentFolder := cfg.fsManager.NewResourceContentFolder(contentData) // NEW FILE: content///index.svx - contentFile := &composer.File{ - Name: cfg.pathMaker.GetResourceContentFilename(), - TemplateID: contentData.Type, - TemplateData: &config.TemplateData{ - Name: contentData.Name, - }, - } + contentFile := cfg.fsManager.NewResourceContentFile(contentData) resourceContentFolder.Add(contentFile) contentFolder.Add(resourceContentFolder) return contentFolder } -func createStaticFolderStructure(contentData *config.TemplateData) *composer.Folder { +func createStaticFolderStructure(contentData *tpltypes.ContentData) *composer.Folder { // GET FOLDER: static staticFolder := cfg.fsManager.GetFolder(StaticFolder) // NEW FOLDER static/resources diff --git a/cmd/addMetadata.go b/cmd/addMetadata.go index 07cdd3e4..df98a5cb 100644 --- a/cmd/addMetadata.go +++ b/cmd/addMetadata.go @@ -24,6 +24,7 @@ import ( "github.com/sveltinio/sveltin/internal/composer" sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/markup" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" ) @@ -71,11 +72,10 @@ func RunAddMetadataCmd(cmd *cobra.Command, args []string) { mdType, err := promptMetadataType(metadataType) utils.ExitIfError(err) - metadataTemplateData := &config.TemplateData{ + metadataTemplateData := &tpltypes.MetadataData{ Name: mdName, Resource: mdResource, Type: mdType, - Config: cfg.sveltin, } headingText := fmt.Sprintf("Creating '%s' as metadata for the '%s' resource", metadataTemplateData.Name, metadataTemplateData.Resource) @@ -207,16 +207,16 @@ func promptMetadataType(mdTypeFlag string) (string, error) { //============================================================================= -func makeOrAddContentForMetadataToProjectStructure(folderName string, metadataTemaplateData *config.TemplateData) (*composer.Folder, error) { +func makeOrAddContentForMetadataToProjectStructure(folderName string, metadataData *tpltypes.MetadataData) (*composer.Folder, error) { switch folderName { case LibFolder: - return createOrAddContentForMetadataToLibLocalFolder(metadataTemaplateData), nil + return createOrAddContentForMetadataToLibLocalFolder(metadataData), nil case ParamsFolder: - return createOrAddContentForMetadataToParamsLocalFolder(metadataTemaplateData), nil + return createOrAddContentForMetadataToParamsLocalFolder(metadataData), nil case RoutesFolder: - return createOrAddContentForMetadataToRoutesLocalFolder(metadataTemaplateData), nil + return createOrAddContentForMetadataToRoutesLocalFolder(metadataData), nil case ApiFolder: - return createOrAddContentForMetadataToApiLocalFolder(metadataTemaplateData), nil + return createOrAddContentForMetadataToApiLocalFolder(metadataData), nil default: err := errors.New("something went wrong: folder not found as mapped resource for sveltin projects") return nil, sveltinerr.NewDefaultError(err) @@ -225,16 +225,19 @@ func makeOrAddContentForMetadataToProjectStructure(folderName string, metadataTe //============================================================================= -func createOrAddContentForMetadataToLibLocalFolder(metadataTemplateData *config.TemplateData) *composer.Folder { +func createOrAddContentForMetadataToLibLocalFolder(metadataData *tpltypes.MetadataData) *composer.Folder { // NEW FILE: api.ts file into src/lib/ folder cfg.log.Info("Lib files") libFile := &composer.File{ - Name: cfg.pathMaker.GetResourceLibFilename(metadataTemplateData.Name), - TemplateID: LibFolder, - TemplateData: metadataTemplateData, + Name: cfg.pathMaker.GetResourceLibFilename(metadataData.Name), + TemplateID: LibFolder, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } // NEW FOLDER: src/lib/ - resourceLibFolder := composer.NewFolder(metadataTemplateData.Resource) + resourceLibFolder := composer.NewFolder(metadataData.Resource) resourceLibFolder.Add(libFile) // GET FOLDER: src/lib folder @@ -244,16 +247,19 @@ func createOrAddContentForMetadataToLibLocalFolder(metadataTemplateData *config. return libFolder } -func createOrAddContentForMetadataToParamsLocalFolder(metadataTemplateData *config.TemplateData) *composer.Folder { +func createOrAddContentForMetadataToParamsLocalFolder(metadataData *tpltypes.MetadataData) *composer.Folder { cfg.log.Info("Parameters matchers") // GET FOLDER: src/params folder paramsFolder := cfg.fsManager.GetFolder(ParamsFolder) // NEW FILE: src/params/.js metadataMatcherFile := &composer.File{ - Name: fmt.Sprintf("%s%s", utils.ToSnakeCase(metadataTemplateData.Name), ".js"), - TemplateID: GenericMatcher, - TemplateData: metadataTemplateData, + Name: fmt.Sprintf("%s%s", utils.ToSnakeCase(metadataData.Name), ".js"), + TemplateID: GenericMatcher, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } // Add file to folder paramsFolder.Add(metadataMatcherFile) @@ -261,17 +267,20 @@ func createOrAddContentForMetadataToParamsLocalFolder(metadataTemplateData *conf return paramsFolder } -func createOrAddContentForMetadataToRoutesLocalFolder(metadataTemaplateData *config.TemplateData) *composer.Folder { +func createOrAddContentForMetadataToRoutesLocalFolder(metadataData *tpltypes.MetadataData) *composer.Folder { cfg.log.Info("Routes") // NEW FOLDER: - resourceMedatadaRoutesFolder := composer.NewFolder(metadataTemaplateData.Name) + resourceMedatadaRoutesFolder := composer.NewFolder(metadataData.Name) // NEW FILE: src/routes///{+page.svelte, +page.server.ts} for _, item := range []string{IndexFile, IndexEndpointFile} { f := &composer.File{ - Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), - TemplateID: item, - TemplateData: metadataTemaplateData, + Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), + TemplateID: item, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } resourceMedatadaRoutesFolder.Add(f) } @@ -281,16 +290,19 @@ func createOrAddContentForMetadataToRoutesLocalFolder(metadataTemaplateData *con // NEW FILE: src/routes//[slug]{+page.svelte, +page.ts} for _, item := range []string{SlugFile, SlugEndpointFile} { f := &composer.File{ - Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), - TemplateID: item, - TemplateData: metadataTemaplateData, + Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), + TemplateID: item, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } slugFolder.Add(f) } resourceMedatadaRoutesFolder.Add(slugFolder) // NEW FOLDER: src/routes// - resourceRoutesFolder := composer.NewFolder(metadataTemaplateData.Resource) + resourceRoutesFolder := composer.NewFolder(metadataData.Resource) resourceRoutesFolder.Add(resourceMedatadaRoutesFolder) // GET FOLDER: src/routes folder @@ -300,34 +312,40 @@ func createOrAddContentForMetadataToRoutesLocalFolder(metadataTemaplateData *con return routesFolder } -func createOrAddContentForMetadataToApiLocalFolder(metadataTemplateData *config.TemplateData) *composer.Folder { +func createOrAddContentForMetadataToApiLocalFolder(metadataData *tpltypes.MetadataData) *composer.Folder { cfg.log.Info("REST endpoint") // GET FOLDER: src/routes/api/ folder apiFolder := cfg.fsManager.GetFolder(ApiFolder) // NEW FOLDER: src/routes/api// - resourceAPIFolder := composer.NewFolder(metadataTemplateData.Resource) + resourceAPIFolder := composer.NewFolder(metadataData.Resource) - // NEW FOLDER: src/routes/api///[ = ] - resourceAPIMetadataMatcherFolder := composer.NewFolder(fmt.Sprintf("%s%s%s%s%s", "[", utils.ToSnakeCase(metadataTemplateData.Resource), "=", utils.ToSnakeCase(metadataTemplateData.Name), "]")) + // NEW FOLDER: src/routes/api/// + resourceAPIMetadataMatcherFolder := composer.NewFolder(utils.ToSnakeCase(metadataData.Name)) - // NEW FILE: src/routes/api///[ = ]/index.ts + // NEW FILE: src/routes/api///[ = ]/+server.ts resourceMetadataIndexAPIFile := &composer.File{ - Name: cfg.sveltin.GetAPIFilename(), - TemplateID: ApiMetadataIndex, - TemplateData: metadataTemplateData, + Name: cfg.sveltin.GetAPIFilename(), + TemplateID: ApiMetadataIndex, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } resourceAPIMetadataMatcherFolder.Add(resourceMetadataIndexAPIFile) resourceAPIFolder.Add(resourceAPIMetadataMatcherFolder) - // NEW FOLDER: src/routes/api///[ = ]/[ = string] - resourceAPIMetadataNameMatcherFolder := composer.NewFolder(fmt.Sprintf("%s%s%s%s%s", "[", utils.ToSnakeCase(metadataTemplateData.Name), "=", "string", "]")) + // NEW FOLDER: src/routes/api////[slug=string] + resourceAPIMetadataNameMatcherFolder := composer.NewFolder("[slug=string]") - // NEW FILE: src/routes/api///[ = ]/[ = string]/index.ts + // NEW FILE: src/routes/api////[slug=string]/+server.ts resourceMetadataNameIndexAPIFile := &composer.File{ - Name: cfg.sveltin.GetAPIFilename(), - TemplateID: ApiFolder, - TemplateData: metadataTemplateData, + Name: cfg.sveltin.GetAPIFilename(), + TemplateID: ApiFolder, + TemplateData: &config.TemplateData{ + Config: cfg.sveltin, + Metadata: metadataData, + }, } resourceAPIMetadataNameMatcherFolder.Add(resourceMetadataNameIndexAPIFile) resourceAPIMetadataMatcherFolder.Add(resourceAPIMetadataNameMatcherFolder) diff --git a/cmd/generateMenu.go b/cmd/generateMenu.go index 8bdcfd02..6c8cbbef 100644 --- a/cmd/generateMenu.go +++ b/cmd/generateMenu.go @@ -10,11 +10,8 @@ package cmd import ( "github.com/spf13/cobra" - "github.com/sveltinio/sveltin/common" - "github.com/sveltinio/sveltin/config" "github.com/sveltinio/sveltin/helpers" "github.com/sveltinio/sveltin/helpers/factory" - "github.com/sveltinio/sveltin/internal/composer" "github.com/sveltinio/sveltin/internal/markup" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" @@ -46,37 +43,23 @@ func RunGenerateMenuCmd(cmd *cobra.Command, args []string) { cfg.log.Plain(markup.H1("Generating the menu structure file")) - projectFolder := cfg.fsManager.GetFolder(RootFolder) + cfg.log.Info("Getting list of all resources contents") + existingResources := helpers.GetAllResources(cfg.fs, cfg.sveltin.GetContentPath()) + contents := helpers.GetResourceContentMap(cfg.fs, existingResources, cfg.sveltin.GetContentPath()) - cfg.log.Info("Getting list of existing public pages") + cfg.log.Info("Getting list of all routes") allRoutes := helpers.GetAllRoutes(cfg.fs, cfg.pathMaker.GetPathToRoutes()) - allResources := helpers.GetAllResources(cfg.fs, cfg.pathMaker.GetPathToExistingResources()) - allRoutesExceptsResource := common.Difference(allRoutes, allResources) - // exclude api folder from the list - publicPages := common.Difference(allRoutesExceptsResource, []string{ApiFolder}) - - cfg.log.Info("Getting list of existing resources") - availableResources := helpers.GetAllResourcesWithContentName(cfg.fs, cfg.pathMaker.GetPathToExistingResources(), withContentFlag) // GET FOLDER: config configFolder := cfg.fsManager.GetFolder(ConfigFolder) // ADD FILE: config/menu.js cfg.log.Info("Saving the menu.js.ts file") - menuFile := &composer.File{ - Name: "menu.js.ts", - TemplateID: "menu", - TemplateData: &config.TemplateData{ - Menu: &config.MenuConfig{ - Resources: availableResources, - Pages: publicPages, - WithContent: withContentFlag, - }, - }, - } + menuFile := cfg.fsManager.NewMenuFile("menu", &cfg.project, allRoutes, contents, withContentFlag) configFolder.Add(menuFile) // SET FOLDER STRUCTURE + projectFolder := cfg.fsManager.GetFolder(RootFolder) projectFolder.Add(configFolder) // GENERATE THE FOLDER TREE diff --git a/cmd/generateRss.go b/cmd/generateRss.go index 9dc4565d..df8ad977 100644 --- a/cmd/generateRss.go +++ b/cmd/generateRss.go @@ -10,7 +10,6 @@ package cmd import ( "github.com/spf13/cobra" - "github.com/sveltinio/sveltin/common" "github.com/sveltinio/sveltin/helpers" "github.com/sveltinio/sveltin/helpers/factory" "github.com/sveltinio/sveltin/internal/markup" @@ -38,25 +37,19 @@ func RunGenerateRSSCmd(cmd *cobra.Command, args []string) { cfg.log.Plain(markup.H1("Generating the RSS feed file")) - cfg.log.Info("Getting all existing resources") + cfg.log.Info("Getting list of all resources contents") existingResources := helpers.GetAllResources(cfg.fs, cfg.pathMaker.GetPathToExistingResources()) - - cfg.log.Info("Getting all resources contents") contents := helpers.GetResourceContentMap(cfg.fs, existingResources, cfg.sveltin.GetContentPath()) - cfg.log.Info("Getting all existing public pages") + cfg.log.Info("Getting list of all routes") allRoutes := helpers.GetAllRoutes(cfg.fs, cfg.pathMaker.GetPathToRoutes()) - allRoutesExceptsResource := common.Difference(allRoutes, existingResources) - // exclude api folder from the list - pages := common.Difference(allRoutesExceptsResource, []string{ApiFolder}) - //pages := helpers.GetAllPublicPages(cfg.fs, cfg.pathMaker.GetPathToPublicPages()) // GET FOLDER: static staticFolder := cfg.fsManager.GetFolder(StaticFolder) // NEW FILE: static/rss.xml cfg.log.Info("Saving the file to the static folder") - rssFile := cfg.fsManager.NewNoPage("rss", &cfg.project, existingResources, contents, nil, pages) + rssFile := cfg.fsManager.NewNoPageFile("rss", &cfg.project, allRoutes, contents) staticFolder.Add(rssFile) // SET FOLDER STRUCTURE diff --git a/cmd/generateSitemap.go b/cmd/generateSitemap.go index 5feb5920..5c143eaa 100644 --- a/cmd/generateSitemap.go +++ b/cmd/generateSitemap.go @@ -10,7 +10,6 @@ package cmd import ( "github.com/spf13/cobra" - "github.com/sveltinio/sveltin/common" "github.com/sveltinio/sveltin/helpers" "github.com/sveltinio/sveltin/helpers/factory" "github.com/sveltinio/sveltin/internal/markup" @@ -38,27 +37,19 @@ func RunGenerateSitemapCmd(cmd *cobra.Command, args []string) { cfg.log.Plain(markup.H1("Generating the sitemap file")) - cfg.log.Info("Getting list of existing resources") - existingResources := helpers.GetAllResources(cfg.fs, cfg.sveltin.GetContentPath()) - cfg.log.Info("Getting list of all resources contents") + existingResources := helpers.GetAllResources(cfg.fs, cfg.sveltin.GetContentPath()) contents := helpers.GetResourceContentMap(cfg.fs, existingResources, cfg.sveltin.GetContentPath()) - cfg.log.Info("Getting list of all resources metadata") - metadata := helpers.GetResourceMetadataMap(cfg.fs, existingResources, cfg.sveltin.GetRoutesPath()) - - cfg.log.Info("Getting all existing public pages") + cfg.log.Info("Getting list of all routes") allRoutes := helpers.GetAllRoutes(cfg.fs, cfg.pathMaker.GetPathToRoutes()) - allRoutesExceptsResource := common.Difference(allRoutes, existingResources) - // exclude api folder from the list - pages := common.Difference(allRoutesExceptsResource, []string{ApiFolder}) // GET FOLDER: static staticFolder := cfg.fsManager.GetFolder(StaticFolder) // NEW FILE: static/rss.xml cfg.log.Info("Saving the file to the static folder") - sitemapFile := cfg.fsManager.NewNoPage("sitemap", &cfg.project, existingResources, contents, metadata, pages) + sitemapFile := cfg.fsManager.NewNoPageFile("sitemap", &cfg.project, allRoutes, contents) staticFolder.Add(sitemapFile) // SET FOLDER STRUCTURE diff --git a/cmd/init.go b/cmd/init.go index 9b457fd6..1963dcaa 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -28,6 +28,7 @@ import ( "github.com/sveltinio/sveltin/internal/markup" "github.com/sveltinio/sveltin/internal/npmc" "github.com/sveltinio/sveltin/internal/shell" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" ) @@ -97,8 +98,10 @@ func InitCmdRun(cmd *cobra.Command, args []string) { // NEW FILE: env.production dotEnvTplData := &config.TemplateData{ - Name: DotEnvProdFile, - BaseURL: fmt.Sprintf("http://%s.com", projectName), + Name: DotEnvProdFile, + Vite: &tpltypes.ViteData{ + BaseURL: fmt.Sprintf("http://%s.com", projectName), + }, } f := cfg.fsManager.NewDotEnvFile(projectName, dotEnvTplData) @@ -122,9 +125,15 @@ func InitCmdRun(cmd *cobra.Command, args []string) { cfg.log.Info("Setting up the CSS Lib") tplData := config.TemplateData{ ProjectName: projectName, - NPMClient: npmClient.ToString(), - PortNumber: withPortNumber, - Theme: themeData, + NPMClient: &tpltypes.NPMClientData{ + Name: npmClient.Name, + Version: npmClient.Version, + Info: npmClient.ToString(), + }, + Vite: &tpltypes.ViteData{ + Port: withPortNumber, + }, + Theme: themeData, } err = setupCSSLib(&resources.SveltinFS, cfg, &tplData) utils.ExitIfError(err) @@ -146,7 +155,7 @@ func InitCmdRun(cmd *cobra.Command, args []string) { } // NEXT STEPS - if themeData.ID != config.ExistingTheme { + if themeData.ID != tpltypes.ExistingTheme { common.PrintNextStepsHelperForNewProject(projectConfigSummary) } else { common.PrintNextStepsHelperForNewProjectWithExistingTheme(projectConfigSummary) @@ -225,8 +234,8 @@ func promptCSSLibName(cssLibName string) (string, error) { func promptThemeSelection(themeFlag string) (string, error) { entries := []list.Item{ - choose.Item{Name: config.BlankTheme, Desc: "Create a new theme"}, - choose.Item{Name: config.SveltinTheme, Desc: "Sveltin default theme"}, + choose.Item{Name: tpltypes.BlankTheme, Desc: "Create a new theme"}, + choose.Item{Name: tpltypes.SveltinTheme, Desc: "Sveltin default theme"}, } switch themeFlagLenght := len(themeFlag); { case themeFlagLenght == 0: @@ -288,9 +297,9 @@ func promptNPMClient(items []string) (string, error) { //============================================================================= -func buildThemeData(themeSelection, themeFlagValue, projectName, cssLibName string) (*config.ThemeData, error) { +func buildThemeData(themeSelection, themeFlagValue, projectName, cssLibName string) (*tpltypes.ThemeData, error) { switch themeSelection { - case config.BlankTheme: + case tpltypes.BlankTheme: defaultThemeName := strings.Join([]string{projectName, "theme"}, "_") newThemePromptContent := &input.Config{ Initial: defaultThemeName, @@ -301,22 +310,22 @@ func buildThemeData(themeSelection, themeFlagValue, projectName, cssLibName stri if err != nil { return nil, err } - return &config.ThemeData{ - ID: config.BlankTheme, + return &tpltypes.ThemeData{ + ID: tpltypes.BlankTheme, IsNew: true, Name: themeName, CSSLib: cssLibName, }, nil - case config.SveltinTheme: - return &config.ThemeData{ - ID: config.SveltinTheme, + case tpltypes.SveltinTheme: + return &tpltypes.ThemeData{ + ID: tpltypes.SveltinTheme, IsNew: false, Name: "sveltin_theme", CSSLib: cssLibName, }, nil - case config.ExistingTheme: - return &config.ThemeData{ - ID: config.ExistingTheme, + case tpltypes.ExistingTheme: + return &tpltypes.ThemeData{ + ID: tpltypes.ExistingTheme, IsNew: false, CSSLib: cssLibName, }, nil @@ -326,15 +335,15 @@ func buildThemeData(themeSelection, themeFlagValue, projectName, cssLibName stri if err != nil { return nil, err } - return &config.ThemeData{ - ID: config.ExistingTheme, + return &tpltypes.ThemeData{ + ID: tpltypes.ExistingTheme, IsNew: false, CSSLib: cssLibName, }, nil } - return &config.ThemeData{ - ID: config.BlankTheme, + return &tpltypes.ThemeData{ + ID: tpltypes.BlankTheme, IsNew: true, Name: getNewThemeName(themeFlagValue, projectName), CSSLib: cssLibName, @@ -390,7 +399,7 @@ func isInitGitRepo(gitFlagValue bool) bool { //============================================================================= -func makeProjectFolderStructure(folderName string, projectName string, themeData *config.ThemeData) (*composer.Folder, error) { +func makeProjectFolderStructure(folderName string, projectName string, themeData *tpltypes.ThemeData) (*composer.Folder, error) { switch folderName { case ConfigFolder: return createProjectConfigLocalFolder(projectName), nil @@ -399,7 +408,7 @@ func makeProjectFolderStructure(folderName string, projectName string, themeData case RoutesFolder: return createProjectRoutesLocalFolder(themeData), nil case ThemesFolder: - if themeData.IsNew || themeData.ID == config.SveltinTheme { + if themeData.IsNew || themeData.ID == tpltypes.SveltinTheme { return createProjectThemeLocalFolder(themeData), nil } return nil, nil @@ -429,7 +438,7 @@ func createProjectContentLocalFolder() *composer.Folder { return composer.NewFolder(ContentFolder) } -func createProjectRoutesLocalFolder(themeData *config.ThemeData) *composer.Folder { +func createProjectRoutesLocalFolder(themeData *tpltypes.ThemeData) *composer.Folder { // GET FOLDER: src/routes folder routesFolder := cfg.fsManager.GetFolder(RoutesFolder) @@ -445,7 +454,7 @@ func createProjectRoutesLocalFolder(themeData *config.ThemeData) *composer.Folde return routesFolder } -func createProjectThemeLocalFolder(themeData *config.ThemeData) *composer.Folder { +func createProjectThemeLocalFolder(themeData *tpltypes.ThemeData) *composer.Folder { // NEW FOLDER: themes themesFolder := composer.NewFolder(ThemesFolder) @@ -475,7 +484,7 @@ func createProjectThemeLocalFolder(themeData *config.ThemeData) *composer.Folder Name: utils.ToMDFile("readme", true), TemplateID: "readme", TemplateData: &config.TemplateData{ - Name: themeData.Name, + Theme: themeData, }, } newThemeFolder.Add(readMeFile) diff --git a/cmd/newPage.go b/cmd/newPage.go index 882b4dcd..d8ca20f3 100644 --- a/cmd/newPage.go +++ b/cmd/newPage.go @@ -21,6 +21,7 @@ import ( "github.com/sveltinio/sveltin/internal/composer" sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/markup" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" ) @@ -65,6 +66,11 @@ func NewPageCmdRun(cmd *cobra.Command, args []string) { pageType, err := promptPageType(pageType) utils.ExitIfError(err) + pageData := &tpltypes.PageData{ + Name: pageName, + Type: pageType, + } + headingText := fmt.Sprintf("Creating the '%s' page (type: %s)", pageName, pageType) cfg.log.Plain(markup.H1(headingText)) @@ -74,7 +80,7 @@ func NewPageCmdRun(cmd *cobra.Command, args []string) { // NEW FOLDER: src/routes/ pageFolder := composer.NewFolder(pageName) // NEW FILE: src/routes//+page.svelte|svx> - pageFile := cfg.fsManager.NewPublicPage(pageName, pageType) + pageFile := cfg.fsManager.NewPublicPageFile(pageData) utils.ExitIfError(err) // ADD TO THE ROUTES FOLDER diff --git a/cmd/newResource.go b/cmd/newResource.go index 357c1409..ff8e2ffb 100644 --- a/cmd/newResource.go +++ b/cmd/newResource.go @@ -20,6 +20,7 @@ import ( "github.com/sveltinio/sveltin/internal/composer" sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/markup" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" @@ -28,9 +29,16 @@ import ( //============================================================================= +var ( + group string + withSlugLayout bool +) + +//============================================================================= + var newResourceCmd = &cobra.Command{ Use: "resource [name]", - Aliases: []string{"r", "route"}, + Aliases: []string{"route", "r"}, Short: "Create a new resource (route).", Long: resources.GetASCIIArt() + ` Command used to create new resources. @@ -61,27 +69,33 @@ func RunNewResourceCmd(cmd *cobra.Command, args []string) { resourceName, err := promptResourceName(args) utils.ExitIfError(err) + resourceData := &tpltypes.ResourceData{ + Name: resourceName, + Group: group, + SlugLayout: withSlugLayout, + } + // MAKE FOLDER STRUCTURE: content folder - headingText := fmt.Sprintf("Creating '%s' as resource", resourceName) + headingText := fmt.Sprintf("Creating '%s' as resource", resourceData.Name) cfg.log.Plain(markup.H1(headingText)) - contentFolder, err := makeResourceFolderStructure(ContentFolder, resourceName, cfg) + contentFolder, err := makeResourceFolderStructure(ContentFolder, resourceData, cfg) utils.ExitIfError(err) // MAKE FOLDER STRUCTURE: src/params - paramsFolder, err := makeResourceFolderStructure(ParamsFolder, resourceName, cfg) + paramsFolder, err := makeResourceFolderStructure(ParamsFolder, resourceData, cfg) utils.ExitIfError(err) // MAKE FOLDER STRUCTURE: src/lib folder - libFolder, err := makeResourceFolderStructure(LibFolder, resourceName, cfg) + libFolder, err := makeResourceFolderStructure(LibFolder, resourceData, cfg) utils.ExitIfError(err) // MAKE FOLDER STRUCTURE: src/routes//{index.svelte, index.ts, [slug].svelte, [slug].json.ts} - routesFolder, err := makeResourceFolderStructure(RoutesFolder, resourceName, cfg) + routesFolder, err := makeResourceFolderStructure(RoutesFolder, resourceData, cfg) utils.ExitIfError(err) // MAKE FOLDER STRUCTURE: src/routes/api/ folder - apiFolder, err := makeResourceFolderStructure(ApiFolder, resourceName, cfg) + apiFolder, err := makeResourceFolderStructure(ApiFolder, resourceData, cfg) utils.ExitIfError(err) // SET FOLDER STRUCTURE @@ -103,8 +117,14 @@ func RunNewResourceCmd(cmd *cobra.Command, args []string) { common.PrintHelperTextNewResource(resourceName) } +func resourceCmdFlags(cmd *cobra.Command) { + cmd.Flags().StringVarP(&group, "group", "g", "", "Group name for resource routes (https://kit.svelte.dev/docs/advanced-routing#advanced-layouts)") + cmd.Flags().BoolVarP(&withSlugLayout, "slug", "", false, "Use a different layout for the slug pages (https://kit.svelte.dev/docs/advanced-routing#advanced-layouts-layout)") +} + func init() { newCmd.AddCommand(newResourceCmd) + resourceCmdFlags(newResourceCmd) } //============================================================================= @@ -131,18 +151,18 @@ func promptResourceName(inputs []string) (string, error) { //============================================================================= -func makeResourceFolderStructure(folderName string, resourceName string, cfg appConfig) (*composer.Folder, error) { +func makeResourceFolderStructure(folderName string, resourceData *tpltypes.ResourceData, cfg appConfig) (*composer.Folder, error) { switch folderName { case ContentFolder: - return createResourceContentLocalFolder(resourceName), nil + return createResourceContentLocalFolder(resourceData), nil case ParamsFolder: - return createResourceParamsLocalFolder(), nil + return createResourceParamsLocalFolder(resourceData), nil case LibFolder: - return createResourceLibLocalFolder(resourceName), nil + return createResourceLibLocalFolder(resourceData), nil case RoutesFolder: - return createResourceRoutesLocalFolder(cfg, resourceName), nil + return createResourceRoutesLocalFolder(cfg, resourceData), nil case ApiFolder: - return createResourceAPIRoutesLocalFolder(resourceName), nil + return createResourceAPIRoutesLocalFolder(resourceData), nil default: err := errors.New("something went wrong: folder not found as mapped resource for sveltin projects") return nil, sveltinerr.NewDefaultError(err) @@ -151,33 +171,34 @@ func makeResourceFolderStructure(folderName string, resourceName string, cfg app //============================================================================= -func createResourceContentLocalFolder(resourceName string) *composer.Folder { +func createResourceContentLocalFolder(resourceData *tpltypes.ResourceData) *composer.Folder { // GET FOLDER: content folder contentFolder := cfg.fsManager.GetFolder(ContentFolder) // NEW FOLDER: content/. Here is where the "new content" command saves files cfg.log.Info("Content folder") - resourceContentFolder := composer.NewFolder(resourceName) + resourceContentFolder := composer.NewFolder(resourceData.Name) contentFolder.Add(resourceContentFolder) return contentFolder } -func createResourceLibLocalFolder(resourceName string) *composer.Folder { +func createResourceLibLocalFolder(resourceData *tpltypes.ResourceData) *composer.Folder { // GET FOLDER: src/lib folder libFolder := cfg.fsManager.GetFolder(LibFolder) // NEW FOLDER: /src/lib/ - resourceLibFolder := composer.NewFolder(resourceName) + resourceLibFolder := composer.NewFolder(resourceData.Name) // NEW FILE: src/lib//load.ts cfg.log.Info("Lib files") libFile := &composer.File{ - Name: utils.ToLibFile(resourceName), + Name: utils.ToLibFile(resourceData.Name), TemplateID: LibFolder, TemplateData: &config.TemplateData{ - Name: resourceName, - Config: cfg.sveltin, + Name: resourceData.Name, + Resource: resourceData, + Config: cfg.sveltin, }, } resourceLibFolder.Add(libFile) @@ -186,7 +207,7 @@ func createResourceLibLocalFolder(resourceName string) *composer.Folder { return libFolder } -func createResourceParamsLocalFolder() *composer.Folder { +func createResourceParamsLocalFolder(resourceData *tpltypes.ResourceData) *composer.Folder { cfg.log.Info("Parameters matchers") // GET FOLDER: src/params folder paramsFolder := cfg.fsManager.GetFolder(ParamsFolder) @@ -196,7 +217,8 @@ func createResourceParamsLocalFolder() *composer.Folder { Name: "string.js", TemplateID: StringMatcher, TemplateData: &config.TemplateData{ - Config: cfg.sveltin, + Resource: resourceData, + Config: cfg.sveltin, }, } // Add file to folder @@ -207,8 +229,9 @@ func createResourceParamsLocalFolder() *composer.Folder { Name: "slug.js", TemplateID: GenericMatcher, TemplateData: &config.TemplateData{ - Name: "slug", - Config: cfg.sveltin, + Name: "slug", + Resource: resourceData, + Config: cfg.sveltin, }, } // Add file to folder @@ -217,12 +240,12 @@ func createResourceParamsLocalFolder() *composer.Folder { return paramsFolder } -func createResourceRoutesLocalFolder(cfg appConfig, resourceName string) *composer.Folder { +func createResourceRoutesLocalFolder(cfg appConfig, resourceData *tpltypes.ResourceData) *composer.Folder { // GET FOLDER: src/routes folder routesFolder := cfg.fsManager.GetFolder(RoutesFolder) // NEW FOLDER: src/routes/ - resourceRoutesFolder := composer.NewFolder(resourceName) + resourceRoutesFolder := composer.NewFolder(resourceData.Name) // NEW FILE: src/routes//{+page.svelte, +page.server.ts} cfg.log.Info("Routes") for _, item := range []string{IndexFile, IndexEndpointFile} { @@ -230,8 +253,9 @@ func createResourceRoutesLocalFolder(cfg appConfig, resourceName string) *compos Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), TemplateID: item, TemplateData: &config.TemplateData{ - Name: resourceName, - Config: cfg.sveltin, + Name: resourceData.Name, + Resource: resourceData, + Config: cfg.sveltin, }, } resourceRoutesFolder.Add(f) @@ -240,38 +264,53 @@ func createResourceRoutesLocalFolder(cfg appConfig, resourceName string) *compos // NEW FOLDER: src/routes//[slug] slugFolder := composer.NewFolder("[slug]") // NEW FILE: src/routes//[slug]{+page.svelte, +page.ts} - for _, item := range []string{SlugFile, SlugEndpointFile} { + slugFiles := []string{SlugFile, SlugEndpointFile} + if resourceData.SlugLayout { + slugFiles = append(slugFiles, SlugLayoutFile) + } + for _, item := range slugFiles { f := &composer.File{ Name: helpers.GetResourceRouteFilename(item, cfg.sveltin), TemplateID: item, TemplateData: &config.TemplateData{ - Name: resourceName, - Config: cfg.sveltin, + Name: resourceData.Name, + Resource: resourceData, + Config: cfg.sveltin, }, } slugFolder.Add(f) } resourceRoutesFolder.Add(slugFolder) - routesFolder.Add(resourceRoutesFolder) + + if utils.IsEmpty(resourceData.Group) { + routesFolder.Add(resourceRoutesFolder) + } else { + // NEW FOLDER: src/routes/(group_name)/ + resourceGroupRoutesFolder := composer.NewFolder(fmt.Sprintf("(%s)", resourceData.Group)) + resourceGroupRoutesFolder.Add(resourceRoutesFolder) + routesFolder.Add(resourceGroupRoutesFolder) + + } return routesFolder } -func createResourceAPIRoutesLocalFolder(resourceName string) *composer.Folder { +func createResourceAPIRoutesLocalFolder(resourceData *tpltypes.ResourceData) *composer.Folder { cfg.log.Info("REST endpoints") // GET FOLDER: src/routes/api/ folder apiFolder := cfg.fsManager.GetFolder(ApiFolder) // NEW FOLDER: src/routes/api// - resourceAPIFolder := composer.NewFolder(resourceName) + resourceAPIFolder := composer.NewFolder(resourceData.Name) // NEW FILE: src/routes/api///+server.ts apiFile := &composer.File{ Name: cfg.sveltin.GetAPIFilename(), TemplateID: ApiIndexFile, TemplateData: &config.TemplateData{ - Name: resourceName, - Config: cfg.sveltin, + Name: resourceData.Name, + Resource: resourceData, + Config: cfg.sveltin, }, } resourceAPIFolder.Add(apiFile) @@ -283,8 +322,9 @@ func createResourceAPIRoutesLocalFolder(resourceName string) *composer.Folder { Name: cfg.sveltin.GetAPIFilename(), TemplateID: ApiSlugFile, TemplateData: &config.TemplateData{ - Name: resourceName, - Config: cfg.sveltin, + Name: resourceData.Name, + Resource: resourceData, + Config: cfg.sveltin, }, } slugStringFolder.Add(apiSlugFile) diff --git a/cmd/newTheme.go b/cmd/newTheme.go index a014a274..a08587ef 100644 --- a/cmd/newTheme.go +++ b/cmd/newTheme.go @@ -27,6 +27,7 @@ import ( sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/markup" "github.com/sveltinio/sveltin/internal/shell" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "github.com/sveltinio/sveltin/utils" ) @@ -84,8 +85,8 @@ func NewThemeCmdRun(cmd *cobra.Command, args []string) { configFolder.Add(f) // MAKE FOLDER STRUCTURE: themes/ folder - themeData := &config.ThemeData{ - ID: config.BlankTheme, + themeData := &tpltypes.ThemeData{ + ID: tpltypes.BlankTheme, IsNew: true, Name: themeName, CSSLib: cssLibName, @@ -110,9 +111,15 @@ func NewThemeCmdRun(cmd *cobra.Command, args []string) { cfg.log.Info("Setting up the CSS Lib") tplData := config.TemplateData{ ProjectName: projectName, - NPMClient: npmClient.ToString(), - PortNumber: withPortNumber, - Theme: themeData, + NPMClient: &tpltypes.NPMClientData{ + Name: npmClient.Name, + Version: npmClient.Version, + Info: npmClient.ToString(), + }, + Vite: &tpltypes.ViteData{ + Port: withPortNumber, + }, + Theme: themeData, } err = setupThemeCSSLib(&resources.SveltinFS, cfg, &tplData) utils.ExitIfError(err) diff --git a/cmd/root.go b/cmd/root.go index 56df678a..66c416a8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,6 +21,7 @@ import ( sveltinerr "github.com/sveltinio/sveltin/internal/errors" "github.com/sveltinio/sveltin/internal/fsm" "github.com/sveltinio/sveltin/internal/pathmaker" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" logger "github.com/sveltinio/yinlog" "gopkg.in/yaml.v3" @@ -31,7 +32,7 @@ import ( type appConfig struct { log *logger.Logger sveltin *config.SveltinConfig - project config.ProjectConfig + project tpltypes.ProjectData pathMaker *pathmaker.SveltinPathMaker fsManager *fsm.SveltinFSManager startersMap map[string]config.StarterTemplate @@ -72,6 +73,7 @@ const ( IndexEndpointFile string = "indexendpoint" SlugFile string = "slug" SlugEndpointFile string = "slugendpoint" + SlugLayoutFile string = "sluglayout" SettingsFile string = ".sveltin-settings.yaml" DotEnvProdFile string = ".env.production" ) @@ -137,7 +139,7 @@ func initAppConfig() { cfg.fs = afero.NewOsFs() } -func loadEnvFile(filename string) (config config.ProjectConfig, err error) { +func loadEnvFile(filename string) (config tpltypes.ProjectData, err error) { currentDir, _ := os.Getwd() viper.AddConfigPath(currentDir) viper.SetConfigName(filename) diff --git a/common/collections.go b/common/collections.go index 4c36c045..9b9e5a0b 100644 --- a/common/collections.go +++ b/common/collections.go @@ -47,7 +47,6 @@ func Unique(s []string) []string { for _, elem := range s { if len(elem) != 0 { if _, value := inResult[elem]; !value { - inResult[elem] = true uniqueValues = append(uniqueValues, elem) } diff --git a/common/messages.go b/common/messages.go index dfe9ee4c..b7304d6f 100644 --- a/common/messages.go +++ b/common/messages.go @@ -12,8 +12,8 @@ import ( "fmt" "strconv" - "github.com/sveltinio/sveltin/config" "github.com/sveltinio/sveltin/internal/markup" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/utils" logger "github.com/sveltinio/yinlog" ) @@ -79,7 +79,7 @@ func PrintHelperTextNewResource(name string) { } // PrintHelperTextNewMetadata prints an help message string for 'metadata creation'. -func PrintHelperTextNewMetadata(metadataInfo *config.TemplateData) { +func PrintHelperTextNewMetadata(metadataInfo *tpltypes.MetadataData) { var exampleString string if metadataInfo.Type == "single" { exampleString = fmt.Sprintf("%s: your_value", utils.ToSnakeCase(metadataInfo.Name)) diff --git a/config/defaults.go b/config/defaults.go index 14fbbb5e..9497ea80 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -11,6 +11,8 @@ package config import ( "os" "path/filepath" + + "github.com/sveltinio/sveltin/internal/tpltypes" ) // IConfig is the interface defining the methods to be implemented. @@ -38,10 +40,10 @@ type IConfig interface { // SveltinConfig is the struct used the map the YAML file. type SveltinConfig struct { - Pages Pages `mapstructure:"pages"` - Paths Paths `mapstructure:"paths"` - API API `mapstructure:"api"` - Theme Theme `mapstructure:"theme"` + Pages Pages `mapstructure:"pages"` + Paths Paths `mapstructure:"paths"` + API API `mapstructure:"api"` + Theme tpltypes.Theme `mapstructure:"theme"` } // GetProjectRoot returns a string representing the current working directory. @@ -146,24 +148,26 @@ func (c *SveltinConfig) GetIndexPageFilename() string { return c.Pages.Index } -// GetIndexEndpointFilename returns a string representing the path to the 'index' -// file relative to the current working directory. +// GetIndexEndpointFilename returns '+page.svelte' file. func (c *SveltinConfig) GetIndexEndpointFilename() string { return c.Pages.IndexEndpoint } -// GetSlugPageFilename returns a string representing the path to the 'slug' -// file relative to the current working directory. +// GetSlugPageFilename returns '+page.svelte' filename for the slug. func (c *SveltinConfig) GetSlugPageFilename() string { return c.Pages.Slug } -// GetSlugEndpointFilename returns a string representing the path to the 'slug' -// file relative to the current working directory. +// GetSlugEndpointFilename returns '+page.ts' as filename for the slug. func (c *SveltinConfig) GetSlugEndpointFilename() string { return c.Pages.SlugEndpoint } +// GetSlugLayoutFilename returns '+layout.svelte' as filename for the slug. +func (c *SveltinConfig) GetSlugLayoutFilename() string { + return c.Pages.SlugLayout +} + // GetContentPageFilename returns a string representing the path to the 'content' folder // relative to the current working directory. func (c *SveltinConfig) GetContentPageFilename() string { diff --git a/config/menu.go b/config/menu.go deleted file mode 100644 index c5b11dda..00000000 --- a/config/menu.go +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright © 2021-present Sveltin contributors - * - * Use of this source code is governed by Apache 2.0 license - * that can be found in the LICENSE file. - */ - -// Package config ... -package config - -// MenuConfig is the struct representing a menu item. -type MenuConfig struct { - Resources []*ResourceItem - Pages []string - WithContent bool -} - -// ResourceItem is a struct representing a resource and its content as menu item. -type ResourceItem struct { - name string - contents []string -} - -// NewResourceItem returns a pointer to a ResourceItem struct. -func NewResourceItem(name string) *ResourceItem { - return &ResourceItem{ - name: name, - contents: []string{}, - } -} - -// GetName returns a string representing the resource item name. -func (r *ResourceItem) GetName() string { - return r.name -} - -// GetContents returns a slice of strings with contents for a resource. -func (r *ResourceItem) GetContents() []string { - return r.contents -} - -// AddChild appends an item to the slice of contents. -func (r *ResourceItem) AddChild(name string) { - r.contents = append(r.contents, name) -} diff --git a/config/pages.go b/config/pages.go index 4d3e704c..8cc126d0 100644 --- a/config/pages.go +++ b/config/pages.go @@ -15,19 +15,5 @@ type Pages struct { IndexEndpoint string `mapstructure:"indexendpoint"` Slug string `mapstructure:"slug"` SlugEndpoint string `mapstructure:"slugendpoint"` -} - -// NoPage is the struct representing a no-public page (sitemap and rss) for a sveltin project. -type NoPage struct { - Config *ProjectConfig - Items *NoPageItems -} - -// NoPageItems is the struct representing an item -// of no-public page (sitemap and rss) for a sveltin project. -type NoPageItems struct { - Resources []string - Content map[string][]string - Metadata map[string][]string - Pages []string + SlugLayout string `mapstructure:"sluglayout"` } diff --git a/config/template_data.go b/config/template_data.go index 87370e63..c401ff0e 100644 --- a/config/template_data.go +++ b/config/template_data.go @@ -8,18 +8,21 @@ // Package config ... package config +import "github.com/sveltinio/sveltin/internal/tpltypes" + // TemplateData is the struct representing all the data to be passed to a template file. type TemplateData struct { ProjectName string - NPMClient string - BaseURL string - PortNumber string Name string - Resource string - Type string Config *SveltinConfig - Menu *MenuConfig - NoPage *NoPage - Theme *ThemeData - Misc string + NPMClient *tpltypes.NPMClientData + Vite *tpltypes.ViteData + Page *tpltypes.PageData + Resource *tpltypes.ResourceData + Content *tpltypes.ContentData + Metadata *tpltypes.MetadataData + Menu *tpltypes.MenuData + NoPage *tpltypes.NoPageData + Theme *tpltypes.ThemeData + Misc *tpltypes.MiscFileData } diff --git a/go.mod b/go.mod index 50d2a2f3..e0220d74 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,17 @@ module github.com/sveltinio/sveltin go 1.17 require ( - github.com/charmbracelet/bubbles v0.13.0 - github.com/charmbracelet/lipgloss v0.5.0 + github.com/charmbracelet/bubbles v0.14.0 + github.com/charmbracelet/lipgloss v0.6.0 github.com/gosimple/slug v1.12.0 - github.com/jlaffaye/ftp v0.0.0-20220904184306-99be0634ab9a + github.com/jlaffaye/ftp v0.1.0 github.com/matryer/is v1.4.0 github.com/spf13/afero v1.9.2 github.com/spf13/cobra v1.5.0 - github.com/spf13/viper v1.12.0 - github.com/sveltinio/prompti v0.0.0-20220821225459-9046be698387 - github.com/sveltinio/yinlog v0.0.0-20220821232519-7f4740f328e2 - github.com/vbauerster/mpb/v8 v8.0.0 + github.com/spf13/viper v1.13.0 + github.com/sveltinio/prompti v0.0.0-20220908083908-d9b8e9284fa8 + github.com/sveltinio/yinlog v0.0.0-20220908084102-7b8c5d8cbde9 + github.com/vbauerster/mpb/v8 v8.0.2 golang.org/x/text v0.3.7 gopkg.in/yaml.v3 v3.0.1 ) @@ -42,16 +42,16 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sahilm/fuzzy v0.1.0 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.3.0 // indirect + github.com/subosito/gotenv v1.4.1 // indirect golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - gopkg.in/ini.v1 v1.66.4 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 70a19806..d4f2e23e 100644 --- a/go.sum +++ b/go.sum @@ -45,14 +45,15 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat6 github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/charmbracelet/bubbles v0.13.0 h1:zP/ROH3wJEBqZWKIsD50ZKKlx3ydLInq3LdD/Nrlb8w= -github.com/charmbracelet/bubbles v0.13.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc= +github.com/charmbracelet/bubbles v0.14.0 h1:DJfCwnARfWjZLvMglhSQzo76UZ2gucuHPy9jLWX45Og= +github.com/charmbracelet/bubbles v0.14.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc= github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4= github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24= github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0= github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= -github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8= github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs= +github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY= +github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -151,8 +152,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jlaffaye/ftp v0.0.0-20220904184306-99be0634ab9a h1:s4ryRQyC5HKZh6qkjNAFcvmD7gImK5bZuj/YZkXy1vw= -github.com/jlaffaye/ftp v0.0.0-20220904184306-99be0634ab9a/go.mod h1:hhq4G4crv+nW2qXtNYcuzLeOudG92Ps37HEKeg2e3lE= +github.com/jlaffaye/ftp v0.1.0 h1:DLGExl5nBoSFoNshAUHwXAezXwXBvFdx7/qwhucWNSE= +github.com/jlaffaye/ftp v0.1.0/go.mod h1:hhq4G4crv+nW2qXtNYcuzLeOudG92Ps37HEKeg2e3lE= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -194,8 +195,8 @@ github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1E github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= -github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= +github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= +github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -220,23 +221,25 @@ github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmq github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ= -github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI= +github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU= +github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI= -github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs= -github.com/sveltinio/prompti v0.0.0-20220821225459-9046be698387 h1:89ScFYdaMb4XjMr4bBN2sPE0G1Y7CQLKIWjXJg5nMBU= -github.com/sveltinio/prompti v0.0.0-20220821225459-9046be698387/go.mod h1:zR5yInXq/desZ+IxGZVfeGtpIcll62mAYYFuPLP1Pg4= -github.com/sveltinio/yinlog v0.0.0-20220821232519-7f4740f328e2 h1:l9kADQhCmdSSCVPCUQhAPdtgTBIE4MoSirvwuYi3G5k= -github.com/sveltinio/yinlog v0.0.0-20220821232519-7f4740f328e2/go.mod h1:DBhoYO25lP2edOHYU7DgBkk2ssxk3ECS696V6beNZdA= -github.com/vbauerster/mpb/v8 v8.0.0 h1:eDv2Lbmv6rb2PgEVNZpnJ9F52L39PjIOyKacnKJzyD8= -github.com/vbauerster/mpb/v8 v8.0.0/go.mod h1:Z9VJYIzXls7xZwirZjShGsi+14enzJhQfGyb/XZK0ZQ= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= +github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/sveltinio/prompti v0.0.0-20220908083908-d9b8e9284fa8 h1:afLpguRGMlrVpMTIMlYvKFuqRrsnvDQtuf2qiXt/YvM= +github.com/sveltinio/prompti v0.0.0-20220908083908-d9b8e9284fa8/go.mod h1:+wW6CvCMWMsPG8+TQcZuD/3XUE+gHfp1sBUTcSZKNiI= +github.com/sveltinio/yinlog v0.0.0-20220908084102-7b8c5d8cbde9 h1:4VNvl3hgvtIj0Cx+FOlTk90FjlRsXoS+6QgRfuPT5IE= +github.com/sveltinio/yinlog v0.0.0-20220908084102-7b8c5d8cbde9/go.mod h1:qwqj9aRSjfvxDFkgN9IbqmY8EGQ1pfBnbemJzZigxX4= +github.com/vbauerster/mpb/v8 v8.0.2 h1:alVQG69Jg5+Ku9Hu1dakDx50uACEHnIzS7i356NQ/Vs= +github.com/vbauerster/mpb/v8 v8.0.2/go.mod h1:Z9VJYIzXls7xZwirZjShGsi+14enzJhQfGyb/XZK0ZQ= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -536,8 +539,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4= -gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/helpers/menu.go b/helpers/menu.go new file mode 100644 index 00000000..3c3f9f11 --- /dev/null +++ b/helpers/menu.go @@ -0,0 +1,11 @@ +package helpers + +import "github.com/sveltinio/sveltin/internal/tpltypes" + +// NewMenuItems return a NoPageItems. +func NewMenuItems(resources []string, content map[string][]string) *tpltypes.MenuItems { + r := new(tpltypes.MenuItems) + r.Resources = resources + r.Content = content + return r +} diff --git a/helpers/pages.go b/helpers/pages.go index b08dd655..863392ab 100644 --- a/helpers/pages.go +++ b/helpers/pages.go @@ -9,29 +9,10 @@ package helpers import ( - "log" - - "github.com/spf13/afero" "github.com/sveltinio/sveltin/config" + "github.com/sveltinio/sveltin/internal/tpltypes" ) -// GetAllRoutes return a slice of all available public page names as string. -func GetAllRoutes(fs afero.Fs, path string) []string { - files, err := afero.ReadDir(fs, path) - if err != nil { - log.Fatalf("Something went wrong visiting the folder %s. Are you sure it exists?", path) - } - - routes := []string{} - for _, f := range files { - if f.IsDir() { - routes = append(routes, f.Name()) - } - } - - return routes -} - // GetResourceRouteFilename returns a string representing the index and slug routes for a resource. func GetResourceRouteFilename(txt string, c *config.SveltinConfig) string { switch txt { @@ -43,6 +24,8 @@ func GetResourceRouteFilename(txt string, c *config.SveltinConfig) string { return c.GetSlugPageFilename() case "slugendpoint": return c.GetSlugEndpointFilename() + case "sluglayout": + return c.GetSlugLayoutFilename() default: return "" } @@ -61,11 +44,9 @@ func PublicPageFilename(pageType string) string { } // NewNoPageItems return a NoPageItems. -func NewNoPageItems(resources []string, content map[string][]string, metadata map[string][]string, pages []string) *config.NoPageItems { - r := new(config.NoPageItems) +func NewNoPageItems(resources []string, content map[string][]string) *tpltypes.NoPageItems { + r := new(tpltypes.NoPageItems) r.Resources = resources r.Content = content - r.Metadata = metadata - r.Pages = pages return r } diff --git a/helpers/pages_test.go b/helpers/pages_test.go index 836fa616..3926618d 100644 --- a/helpers/pages_test.go +++ b/helpers/pages_test.go @@ -9,6 +9,7 @@ import ( "github.com/matryer/is" "github.com/spf13/afero" "github.com/sveltinio/sveltin/config" + "github.com/sveltinio/sveltin/internal/tpltypes" "gopkg.in/yaml.v3" ) @@ -19,15 +20,18 @@ func TestPublicPageFilename(t *testing.T) { }{ { pageData: &config.TemplateData{ - Name: "index", - Type: "svelte", + Page: &tpltypes.PageData{ + Name: "index", + Type: "svelte"}, }, want: "+page.svelte", }, { pageData: &config.TemplateData{ - Name: "about", - Type: "markdown", + Page: &tpltypes.PageData{ + Name: "about", + Type: "markdown", + }, }, want: "+page.svx", }, @@ -35,7 +39,7 @@ func TestPublicPageFilename(t *testing.T) { for _, tc := range tests { is := is.New(t) - is.Equal(PublicPageFilename(tc.pageData.Type), tc.want) + is.Equal(PublicPageFilename(tc.pageData.Page.Type), tc.want) } } diff --git a/helpers/resources.go b/helpers/resources.go index 3c08b00e..1298047d 100644 --- a/helpers/resources.go +++ b/helpers/resources.go @@ -10,7 +10,9 @@ package helpers import ( "log" + "os" "path/filepath" + "regexp" "strings" "github.com/spf13/afero" @@ -45,36 +47,52 @@ func GetAllResources(fs afero.Fs, path string) []string { return resources } -// GetAllResourcesWithContentName traverses the resource contents and returns a slice of ResourceItem. -func GetAllResourcesWithContentName(fs afero.Fs, path string, children bool) []*config.ResourceItem { - var result []*config.ResourceItem - exists, _ := afero.DirExists(fs, path) - if exists { - files, err := afero.ReadDir(fs, path) - if err != nil { - log.Fatalf("Something went wrong visiting the folder %s. Are you sure it exists?", path) - } - for _, f := range files { - if f.IsDir() { - item := config.NewResourceItem(f.Name()) - if children { - subFolders, err := afero.ReadDir(fs, filepath.Join(path, f.Name())) - if err != nil { - log.Fatalf("Something went wrong visiting the subfolder %s. Are you sure it exists?", f.Name()) - } - for _, s := range subFolders { - if s.IsDir() { - item.AddChild(s.Name()) +// GetAllRoutes return a slice of all routes names as string. +func GetAllRoutes(fs afero.Fs, path string) []string { + entries := []string{} + if common.DirExists(fs, path) { + walkFunc := func(filepath string, info os.FileInfo, err error) error { + if info.IsDir() { + replacer := strings.NewReplacer(path, "", "/[slug]", "") + res := replacer.Replace(filepath) + res = strings.TrimSpace(res) + + if !strings.HasPrefix(res, "/api") { + // Match (group) name + re := regexp.MustCompile(`\/\((.*?)\)`) + if re.MatchString(res) { + submatchall := re.FindAllString(res, -1) + + for _, element := range submatchall { + element = strings.ReplaceAll(res, element, "") + element = strings.Replace(element, "/", "", 1) + + if !common.Contains(entries, element) { + entries = append(entries, element) + } + } + } else { + if !common.Contains(entries, res) { + entries = append(entries, res) } } } - result = append(result, item) - + return nil } + return nil + } + + err := afero.Walk(fs, path, walkFunc) + if err != nil { + log.Fatalf("Something went wrong visiting the folder %s. Are you sure it exists?", path) } } - return result + routes := []string{} + for _, file := range entries { + routes = append(routes, strings.Replace(file, "/", "", 1)) + } + return common.Unique(routes) } // GetResourceContentMap returns a map of resources and relative contents. diff --git a/helpers/templates.go b/helpers/templates.go index 71868d4c..ddba59db 100644 --- a/helpers/templates.go +++ b/helpers/templates.go @@ -9,14 +9,40 @@ package helpers import ( + "bytes" + "embed" + "log" + "path/filepath" template "text/template" "github.com/sveltinio/sveltin/config" ) +// TplConfig is the struct representing all is needed by a template file +// (path to the template, functions map and template data). +type TplConfig struct { + PathToTplFile string + Funcs template.FuncMap + Data config.TemplateData +} + +// Run executes the templates and return the content as []byte. +func (tplConfig *TplConfig) Run(embedFS *embed.FS) []byte { + pathToTplFile := tplConfig.PathToTplFile + tplFilename := filepath.Base(tplConfig.PathToTplFile) + funcMap := tplConfig.Funcs + + tmpl := template.Must(template.New(tplFilename).Funcs(funcMap).ParseFS(embedFS, pathToTplFile)) + var writer bytes.Buffer + if err := tmpl.ExecuteTemplate(&writer, tplFilename, tplConfig.Data); err != nil { + log.Fatalln(err.Error()) + } + return writer.Bytes() +} + // BuildTemplate creates TplConfig struct with all is needed for a golang template to be executed -func BuildTemplate(tplPath string, funcs template.FuncMap, data *config.TemplateData) *config.TplConfig { - c := new(config.TplConfig) +func BuildTemplate(tplPath string, funcs template.FuncMap, data *config.TemplateData) *TplConfig { + c := new(TplConfig) c.PathToTplFile = tplPath c.Funcs = funcs c.Data = *data diff --git a/helpers/templates_test.go b/helpers/templates_test.go index d3d53569..436a4e1b 100644 --- a/helpers/templates_test.go +++ b/helpers/templates_test.go @@ -10,6 +10,7 @@ import ( "github.com/matryer/is" "github.com/spf13/afero" "github.com/sveltinio/sveltin/config" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" "gopkg.in/yaml.v3" ) @@ -42,7 +43,7 @@ func TestExecSveltinTpl(t *testing.T) { pathToTplFile := resources.SveltinProjectFS["theme_config"] data := config.TemplateData{ - Theme: &config.ThemeData{ + Theme: &tpltypes.ThemeData{ Name: "white", }, } diff --git a/internal/builder/constants.go b/internal/builder/constants.go index 893cc8dc..f5b92f57 100644 --- a/internal/builder/constants.go +++ b/internal/builder/constants.go @@ -73,6 +73,8 @@ const ( Slug string = "slug" // SlugEndpoint is the string for the 'slug' file. SlugEndpoint string = "slugendpoint" + // SlugLayout is the string from the 'layout' file + SlugLayout string = "sluglayout" //============================================================================= diff --git a/internal/builder/menu_builder.go b/internal/builder/menu_builder.go index ab1e573a..25e365fb 100644 --- a/internal/builder/menu_builder.go +++ b/internal/builder/menu_builder.go @@ -9,6 +9,7 @@ package builder import ( + "path/filepath" "strings" "text/template" @@ -57,16 +58,20 @@ func (b *MenuContentBuilder) SetTemplateData(artifactData *config.TemplateData) func (b *MenuContentBuilder) setFuncs() { b.Funcs = template.FuncMap{ + "StringsJoin": strings.Join, + "Base": filepath.Base, "Capitalize": func(txt string) string { return utils.ToTitle(txt) }, - "StringsJoin": strings.Join, "ToURL": func(txt string) string { return utils.ToURL(txt) }, "PlusOne": func(x int) int { return utils.PlusOne(x) }, + "MinusOne": func(x int) int { + return utils.MinusOne(x) + }, "Sum": func(x int, y int) int { return utils.Sum(x, y) }, diff --git a/internal/builder/metadata_builder.go b/internal/builder/metadata_builder.go index bd81a8b2..7ff73c75 100644 --- a/internal/builder/metadata_builder.go +++ b/internal/builder/metadata_builder.go @@ -47,9 +47,9 @@ func (b *MetadataContentBuilder) setPathToTplFile() error { b.PathToTplFile = b.EmbeddedResources[ApiMetadataIndex] return nil case ApiFolder: - if b.TemplateData.Type == "single" { + if b.TemplateData.Metadata.Type == "single" { b.PathToTplFile = b.EmbeddedResources[ApiMetadataSingle] - } else if b.TemplateData.Type == "list" { + } else if b.TemplateData.Metadata.Type == "list" { b.PathToTplFile = b.EmbeddedResources[ApiMetadataList] } return nil @@ -69,9 +69,9 @@ func (b *MetadataContentBuilder) setPathToTplFile() error { b.PathToTplFile = b.EmbeddedResources[SlugEndpoint] return nil case Lib: - if b.TemplateData.Type == "single" { + if b.TemplateData.Metadata.Type == "single" { b.PathToTplFile = b.EmbeddedResources[LibSingle] - } else if b.TemplateData.Type == "list" { + } else if b.TemplateData.Metadata.Type == "list" { b.PathToTplFile = b.EmbeddedResources[LibList] } return nil diff --git a/internal/builder/project_builder.go b/internal/builder/project_builder.go index e65ef55f..3155adf4 100644 --- a/internal/builder/project_builder.go +++ b/internal/builder/project_builder.go @@ -14,6 +14,7 @@ import ( "github.com/sveltinio/sveltin/config" sveltinerr "github.com/sveltinio/sveltin/internal/errors" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/utils" ) @@ -68,7 +69,7 @@ func (b *ProjectBuilder) setPathToTplFile() error { b.PathToTplFile = b.EmbeddedResources[ThemeConfig] return nil case IndexPage: - if b.TemplateData.Theme.ID == config.ExistingTheme { + if b.TemplateData.Theme.ID == tpltypes.ExistingTheme { b.PathToTplFile = b.EmbeddedResources[IndexNoThemePage] } else { b.PathToTplFile = b.EmbeddedResources[IndexPage] diff --git a/internal/builder/resource_builder.go b/internal/builder/resource_builder.go index a9a1c04f..6f8a08e6 100644 --- a/internal/builder/resource_builder.go +++ b/internal/builder/resource_builder.go @@ -67,6 +67,9 @@ func (b *ResourceContentBuilder) setPathToTplFile() error { case SlugEndpoint: b.PathToTplFile = b.EmbeddedResources[SlugEndpoint] return nil + case SlugLayout: + b.PathToTplFile = b.EmbeddedResources[SlugLayout] + return nil case Lib: b.PathToTplFile = b.EmbeddedResources[Lib] return nil diff --git a/internal/css/cssframework.go b/internal/css/cssframework.go index 1ccc17a2..848f1349 100644 --- a/internal/css/cssframework.go +++ b/internal/css/cssframework.go @@ -17,6 +17,7 @@ import ( "github.com/sveltinio/sveltin/config" "github.com/sveltinio/sveltin/helpers" sveltinerr "github.com/sveltinio/sveltin/internal/errors" + "github.com/sveltinio/sveltin/internal/tpltypes" "github.com/sveltinio/sveltin/resources" ) @@ -38,14 +39,14 @@ func (cssLib *CSSLib) Setup(isNewProject bool) error { // When creating a fresh new Project (sveltin new ) switch cssLib.TplData.Theme.ID { - case config.BlankTheme: + case tpltypes.BlankTheme: return makeUnstyled(cssLib) - case config.SveltinTheme: + case tpltypes.SveltinTheme: return makeSveltinStyled(cssLib) - case config.ExistingTheme: + case tpltypes.ExistingTheme: return makeTheme(cssLib) default: - return sveltinerr.NewOptionNotValidError(cssLib.TplData.Theme.Name, config.AvailableThemes[:]) + return sveltinerr.NewOptionNotValidError(cssLib.TplData.Theme.Name, tpltypes.AvailableThemes[:]) } } diff --git a/internal/fsm/sveltin_fsm.go b/internal/fsm/sveltin_fsm.go index 12c4f0f4..0b8fce5b 100644 --- a/internal/fsm/sveltin_fsm.go +++ b/internal/fsm/sveltin_fsm.go @@ -16,6 +16,7 @@ import ( "github.com/sveltinio/sveltin/helpers" "github.com/sveltinio/sveltin/internal/composer" "github.com/sveltinio/sveltin/internal/pathmaker" + "github.com/sveltinio/sveltin/internal/tpltypes" ) // SveltinFSManager is the struct for a pathmaker. @@ -57,41 +58,55 @@ func (s *SveltinFSManager) GetFolder(name string) *composer.Folder { } // NewResourceContentFolder returns a pointer to the 'resource content' Folder. -func (s *SveltinFSManager) NewResourceContentFolder(name string, resource string) *composer.Folder { - return composer.NewFolder(filepath.Join(resource, name)) +func (s *SveltinFSManager) NewResourceContentFolder(contentData *tpltypes.ContentData) *composer.Folder { + return composer.NewFolder(filepath.Join(contentData.Resource, contentData.Name)) } // NewResourceContentFile returns a pointer to the 'resource content' File. -func (s *SveltinFSManager) NewResourceContentFile(name string, template string) *composer.File { +func (s *SveltinFSManager) NewResourceContentFile(contentData *tpltypes.ContentData) *composer.File { return &composer.File{ Name: s.maker.GetResourceContentFilename(), - TemplateID: template, + TemplateID: contentData.Type, TemplateData: &config.TemplateData{ - Name: name, + Content: contentData, }, } } -// NewPublicPage returns a pointer to a new 'public page' File. -func (s *SveltinFSManager) NewPublicPage(name string, language string) *composer.File { +// NewPublicPageFile returns a pointer to a new 'public page' File. +func (s *SveltinFSManager) NewPublicPageFile(pageData *tpltypes.PageData) *composer.File { return &composer.File{ - Name: helpers.PublicPageFilename(language), - TemplateID: language, + Name: helpers.PublicPageFilename(pageData.Type), + TemplateID: pageData.Type, TemplateData: &config.TemplateData{ - Name: name, + Page: pageData, }, } } -// NewNoPage returns a pointer to a 'no-public page' File. -func (s *SveltinFSManager) NewNoPage(name string, projectConfig *config.ProjectConfig, resources []string, contents map[string][]string, metadata map[string][]string, pages []string) *composer.File { +// NewNoPageFile returns a pointer to a 'no-public page' File. +func (s *SveltinFSManager) NewNoPageFile(name string, projectConfig *tpltypes.ProjectData, resources []string, contents map[string][]string) *composer.File { return &composer.File{ Name: name + ".xml", TemplateID: name, TemplateData: &config.TemplateData{ - NoPage: &config.NoPage{ + NoPage: &tpltypes.NoPageData{ Config: projectConfig, - Items: helpers.NewNoPageItems(resources, contents, metadata, pages), + Items: helpers.NewNoPageItems(resources, contents), + }, + }, + } +} + +// NewMenuFile returns a pointer to a 'no-public page' File. +func (s *SveltinFSManager) NewMenuFile(name string, projectConfig *tpltypes.ProjectData, resources []string, contents map[string][]string, withContentFlag bool) *composer.File { + return &composer.File{ + Name: name + ".js.ts", + TemplateID: name, + TemplateData: &config.TemplateData{ + Menu: &tpltypes.MenuData{ + Items: helpers.NewMenuItems(resources, contents), + WithContent: withContentFlag, }, }, } @@ -105,8 +120,10 @@ func (s *SveltinFSManager) NewConfigFile(projectName string, name string, cliVer TemplateID: name, TemplateData: &config.TemplateData{ ProjectName: projectName, - Name: filename, - Misc: cliVersion, + Misc: &tpltypes.MiscFileData{ + Name: filename, + Info: cliVersion, + }, }, } } @@ -119,14 +136,3 @@ func (s *SveltinFSManager) NewDotEnvFile(projectName string, tplData *config.Tem TemplateData: tplData, } } - -// NewContentFile returns a pointer to a new 'content' File. -func (s *SveltinFSManager) NewContentFile(name string, template string, resource string) *composer.File { - return &composer.File{ - Name: s.maker.GetResourceContentFilename(), - TemplateID: template, - TemplateData: &config.TemplateData{ - Name: name, - }, - } -} diff --git a/internal/tpltypes/content.go b/internal/tpltypes/content.go new file mode 100644 index 00000000..74504681 --- /dev/null +++ b/internal/tpltypes/content.go @@ -0,0 +1,15 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// ContentData is the struct representing the user configs for the new resource. +type ContentData struct { + Name string + Resource string + Type string +} diff --git a/internal/tpltypes/menu.go b/internal/tpltypes/menu.go new file mode 100644 index 00000000..de1c1ebb --- /dev/null +++ b/internal/tpltypes/menu.go @@ -0,0 +1,21 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// MenuData is the struct representing a menu item. +type MenuData struct { + Items *MenuItems + WithContent bool +} + +// MenuItems is a struct representing a resource and its content as menu item. +type MenuItems struct { + Name string + Resources []string + Content map[string][]string +} diff --git a/internal/tpltypes/metadata.go b/internal/tpltypes/metadata.go new file mode 100644 index 00000000..7b2ad26e --- /dev/null +++ b/internal/tpltypes/metadata.go @@ -0,0 +1,15 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// MetadataData is the struct representing the user configs for the new resource. +type MetadataData struct { + Name string + Resource string + Type string +} diff --git a/internal/tpltypes/miscfile.go b/internal/tpltypes/miscfile.go new file mode 100644 index 00000000..8e1e8afd --- /dev/null +++ b/internal/tpltypes/miscfile.go @@ -0,0 +1,15 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// MiscFileData is the struct representing the user configs for the new resource. +type MiscFileData struct { + Name string + Type string + Info string +} diff --git a/internal/tpltypes/nopage.go b/internal/tpltypes/nopage.go new file mode 100644 index 00000000..6324d28f --- /dev/null +++ b/internal/tpltypes/nopage.go @@ -0,0 +1,21 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// NoPageData is the struct representing a no-public page (sitemap and rss) for a sveltin project. +type NoPageData struct { + Config *ProjectData + Items *NoPageItems +} + +// NoPageItems is the struct representing an item +// of no-public page (sitemap and rss) for a sveltin project. +type NoPageItems struct { + Resources []string + Content map[string][]string +} diff --git a/internal/tpltypes/npmclient.go b/internal/tpltypes/npmclient.go new file mode 100644 index 00000000..21673a14 --- /dev/null +++ b/internal/tpltypes/npmclient.go @@ -0,0 +1,15 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// NPMClientData is the struct representing the user configs for the new resource. +type NPMClientData struct { + Name string + Version string + Info string +} diff --git a/internal/tpltypes/page.go b/internal/tpltypes/page.go new file mode 100644 index 00000000..a1c1efb1 --- /dev/null +++ b/internal/tpltypes/page.go @@ -0,0 +1,14 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// PageData is the struct representing the user configs for the new resource. +type PageData struct { + Name string + Type string +} diff --git a/internal/tpltypes/project.go b/internal/tpltypes/project.go new file mode 100644 index 00000000..8d2183b3 --- /dev/null +++ b/internal/tpltypes/project.go @@ -0,0 +1,24 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +// Package tpltypes ... +package tpltypes + +// ProjectData is the struct used to map the env.production file props. +type ProjectData struct { + BaseURL string `mapstructure:"VITE_PUBLIC_BASE_PATH"` + SitemapChangeFreq string `mapstructure:"sitemapChangeFreq"` + SitemapPriority string `mapstructure:"sitemapPriority"` + SvelteKitBuildFolder string `mapstructure:"SVELTEKIT_BUILD_FOLDER"` + FTPHost string `mapstructure:"FTP_HOST"` + FTPPort int `mapstructure:"FTP_PORT"` + FTPUser string `mapstructure:"FTP_USER"` + FTPPassword string `mapstructure:"FTP_PASSWORD"` + FTPServerFolder string `mapstructure:"FTP_SERVER_FOLDER"` + FTPDialTimeout int `mapstructure:"FTP_DIAL_TIMEOUT"` + FTPEPSVMode bool `mapstructure:"FTP_EPSV"` +} diff --git a/internal/tpltypes/resource.go b/internal/tpltypes/resource.go new file mode 100644 index 00000000..0c73ef74 --- /dev/null +++ b/internal/tpltypes/resource.go @@ -0,0 +1,15 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// ResourceData is the struct representing the user configs for the new resource. +type ResourceData struct { + Name string + Group string + SlugLayout bool +} diff --git a/config/theme.go b/internal/tpltypes/theme.go similarity index 95% rename from config/theme.go rename to internal/tpltypes/theme.go index 8c685f2a..67499d59 100644 --- a/config/theme.go +++ b/internal/tpltypes/theme.go @@ -5,8 +5,8 @@ * that can be found in the LICENSE file. */ -// Package config ... -package config +// Package tpltypes ... +package tpltypes // names for the available thems options. const ( diff --git a/internal/tpltypes/vite.go b/internal/tpltypes/vite.go new file mode 100644 index 00000000..53b2ffc9 --- /dev/null +++ b/internal/tpltypes/vite.go @@ -0,0 +1,14 @@ +/** + * Copyright © 2021-present Sveltin contributors + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package tpltypes + +// ViteData is the struct representing the user configs for the new resource. +type ViteData struct { + BaseURL string + Port string +} diff --git a/resources/defaults.go b/resources/defaults.go index 5883e761..762cbd56 100644 --- a/resources/defaults.go +++ b/resources/defaults.go @@ -55,6 +55,7 @@ var SveltinResourceFS = map[string]string{ "indexendpoint": "internal/templates/resource/page.server.ts.gotxt", "slug": "internal/templates/resource/slug.svelte.gotxt", "slugendpoint": "internal/templates/resource/slug.ts.gotxt", + "sluglayout": "internal/templates/resource/layout.svelte.gotxt", } // SveltinAPIFS is the map for the api template files. diff --git a/resources/internal/templates/content/blank.svx.gotxt b/resources/internal/templates/content/blank.svx.gotxt index fd7fcb4f..57138697 100644 --- a/resources/internal/templates/content/blank.svx.gotxt +++ b/resources/internal/templates/content/blank.svx.gotxt @@ -1,7 +1,7 @@ --- -title: {{ .Name | ToTitle }} +title: {{ .Content.Name | ToTitle }} author: YOUR_NAME -slug: {{ .Name | ToSlug }} +slug: {{ .Content.Name | ToSlug }} headline: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porttitor eget elit vel semper. Cras. created_at: {{ Today }} updated_at: {{ Today }} diff --git a/resources/internal/templates/content/sample.svx.gotxt b/resources/internal/templates/content/sample.svx.gotxt index 59879a69..a723fcff 100644 --- a/resources/internal/templates/content/sample.svx.gotxt +++ b/resources/internal/templates/content/sample.svx.gotxt @@ -1,7 +1,7 @@ --- -title: {{ .Name | ToTitle }} +title: {{ .Content.Name | ToTitle }} author: YOUR_NAME -slug: {{ .Name | ToSlug }} +slug: {{ .Content.Name | ToSlug }} headline: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porttitor eget elit vel semper. Cras. created_at: {{ Today }} updated_at: {{ Today }} diff --git a/resources/internal/templates/misc/README.md.gotxt b/resources/internal/templates/misc/README.md.gotxt index 8a1a6c7a..a4644ec3 100644 --- a/resources/internal/templates/misc/README.md.gotxt +++ b/resources/internal/templates/misc/README.md.gotxt @@ -1,3 +1,3 @@ -# {{ .Name }} theme +# {{ .Theme.Name }} theme Sveltin autogenerated README file diff --git a/resources/internal/templates/misc/env.gotxt b/resources/internal/templates/misc/env.gotxt index 7c872fe2..e992e873 100644 --- a/resources/internal/templates/misc/env.gotxt +++ b/resources/internal/templates/misc/env.gotxt @@ -1,4 +1,4 @@ -VITE_PUBLIC_BASE_PATH={{ .BaseURL }} +VITE_PUBLIC_BASE_PATH={{ .Vite.BaseURL }} sitemapChangeFreq = "monthly" sitemapPriority = "0.5" @@ -8,7 +8,7 @@ SVELTEKIT_BUILD_FOLDER = "build" # FTP Server config section FTP_HOST = "" -FTP_PORT = +FTP_PORT = 21 FTP_USER = "" FTP_PASSWORD = "" FTP_SERVER_FOLDER = "" diff --git a/resources/internal/templates/page/page.svelte.gotxt b/resources/internal/templates/page/page.svelte.gotxt index 576dbf60..9c0117b7 100644 --- a/resources/internal/templates/page/page.svelte.gotxt +++ b/resources/internal/templates/page/page.svelte.gotxt @@ -1,4 +1,4 @@ -{{ $pageName := .Name | ToVariableName}} +{{- $pageName := .Page.Name | ToVariableName -}} + + diff --git a/resources/internal/templates/resource/lib.gotxt b/resources/internal/templates/resource/lib.gotxt index 08cf069c..8ad87411 100644 --- a/resources/internal/templates/resource/lib.gotxt +++ b/resources/internal/templates/resource/lib.gotxt @@ -1,7 +1,7 @@ import type { Sveltin } from 'src/sveltin'; export async function list() { - const contentFiles = import.meta.glob('/{{ .Config.Paths.Content }}/{{ .Name }}/**/*.{svelte.md,md,svx}'); + const contentFiles = import.meta.glob('/{{ .Config.Paths.Content }}/{{ .Resource.Name }}/**/*.{svelte.md,md,svx}'); const contentFilesArray = Object.entries(contentFiles); const contents = await Promise.all( contentFilesArray.map(async ([path, resolver]) => { @@ -20,7 +20,7 @@ export async function list() { return publishedByDate; }; -{{ $slugName := .Name | ToSlug}} +{{ $slugName := .Resource.Name | ToSlug}} export async function getSingle(slug: string) { const resourceName = '{{ $slugName }}'; const publishedByDate = await list(); diff --git a/resources/internal/templates/resource/metadata/libList.gotxt b/resources/internal/templates/resource/metadata/libList.gotxt index e2fa9853..f8764213 100644 --- a/resources/internal/templates/resource/metadata/libList.gotxt +++ b/resources/internal/templates/resource/metadata/libList.gotxt @@ -1,5 +1,5 @@ -{{ $resourceName := .Resource | ToVariableName | Capitalize }} -{{ $mdName := .Name | ToSnakeCase }} +{{- $resourceName := .Metadata.Resource | ToVariableName | Capitalize -}} +{{- $mdName := .Metadata.Name | ToSnakeCase -}} import type { Sveltin } from 'src/sveltin'; import { groupedByMany } from '$lib/utils/collections.js'; import { list } from './load{{ $resourceName }}'; diff --git a/resources/internal/templates/resource/metadata/libSingle.gotxt b/resources/internal/templates/resource/metadata/libSingle.gotxt index 94191c1f..db6ffae3 100644 --- a/resources/internal/templates/resource/metadata/libSingle.gotxt +++ b/resources/internal/templates/resource/metadata/libSingle.gotxt @@ -1,5 +1,5 @@ -{{ $resourceName := .Resource | ToVariableName | Capitalize }} -{{ $mdName := .Name | ToSnakeCase }} +{{- $resourceName := .Metadata.Resource | ToVariableName | Capitalize -}} +{{- $mdName := .Metadata.Name | ToSnakeCase -}} import type { Sveltin } from 'src/sveltin'; import { groupedByOne } from '$lib/utils/collections.js'; import { list } from './load{{ $resourceName }}'; diff --git a/resources/internal/templates/resource/metadata/page.server.ts.gotxt b/resources/internal/templates/resource/metadata/page.server.ts.gotxt index aa3d2279..a06ea6e0 100644 --- a/resources/internal/templates/resource/metadata/page.server.ts.gotxt +++ b/resources/internal/templates/resource/metadata/page.server.ts.gotxt @@ -1,6 +1,6 @@ import type { Sveltin } from 'src/sveltin'; -{{ $mdName := .Name | ToVariableName | Capitalize}} -import { all } from '$lib/{{ .Resource }}/load{{ $mdName }}'; +{{- $mdName := .Metadata.Name | ToVariableName | Capitalize -}} +import { all } from '$lib/{{ .Metadata.Resource }}/load{{ $mdName }}'; export async function load() { const data = await all(); diff --git a/resources/internal/templates/resource/metadata/page.svelte.gotxt b/resources/internal/templates/resource/metadata/page.svelte.gotxt index 7c2f457a..2297e9d2 100644 --- a/resources/internal/templates/resource/metadata/page.svelte.gotxt +++ b/resources/internal/templates/resource/metadata/page.svelte.gotxt @@ -5,24 +5,24 @@ export let data: PageData; $: ({ metadata } = data); -{{ $mdName := .Name | ToVariableName}} +{{ $mdName := .Metadata.Name | ToVariableName}}
-

Grouped by {{ .Name | Capitalize }}

+

Grouped by {{ .Metadata.Name | Capitalize }}

{#if metadata.length != 0} {#each metadata as {{ $mdName}} }

- { {{ $mdName }}.name} + { {{ $mdName }}.name}

{/each} {:else}

- Please, check all your content ensuring the YAML frontmatter contains "{{ .Name | ToVariableName}}". + Please, check all your content ensuring the YAML frontmatter contains "{{ .Metadata.Name | ToVariableName}}".

{/if}
diff --git a/resources/internal/templates/resource/metadata/slug.svelte.gotxt b/resources/internal/templates/resource/metadata/slug.svelte.gotxt index 6577037e..78d5576e 100644 --- a/resources/internal/templates/resource/metadata/slug.svelte.gotxt +++ b/resources/internal/templates/resource/metadata/slug.svelte.gotxt @@ -13,7 +13,7 @@

{slug} [ Total: {itemsCounter} ]

{:else} diff --git a/resources/internal/templates/resource/metadata/slug.ts.gotxt b/resources/internal/templates/resource/metadata/slug.ts.gotxt index 3f4f1040..c619a742 100644 --- a/resources/internal/templates/resource/metadata/slug.ts.gotxt +++ b/resources/internal/templates/resource/metadata/slug.ts.gotxt @@ -1,5 +1,5 @@ -{{ $mdName := .Name | ToVariableName | Capitalize }} -import { groupedBy } from '$lib/{{ .Resource }}/load{{ $mdName }}'; +{{- $mdName := .Metadata.Name | ToVariableName | Capitalize -}} +import { groupedBy } from '$lib/{{ .Metadata.Resource }}/load{{ $mdName }}'; import { error } from '@sveltejs/kit'; export async function load({ params }) { diff --git a/resources/internal/templates/resource/page.server.ts.gotxt b/resources/internal/templates/resource/page.server.ts.gotxt index 27d3a7b4..04bca948 100644 --- a/resources/internal/templates/resource/page.server.ts.gotxt +++ b/resources/internal/templates/resource/page.server.ts.gotxt @@ -1,8 +1,8 @@ import type { Sveltin } from 'src/sveltin'; -import { list } from '$lib/{{ .Name }}/load{{ .Name | ToVariableName | Capitalize }}'; +import { list } from '$lib/{{ .Resource.Name }}/load{{ .Resource.Name | ToVariableName | Capitalize }}'; export async function load() { - const resourceName = '{{ .Name }}'; + const resourceName = '{{ .Resource.Name }}'; const data = await list(); const items: Array = []; diff --git a/resources/internal/templates/resource/page.svelte.gotxt b/resources/internal/templates/resource/page.svelte.gotxt index 5bfeac2f..3a9fed40 100644 --- a/resources/internal/templates/resource/page.svelte.gotxt +++ b/resources/internal/templates/resource/page.svelte.gotxt @@ -1,4 +1,4 @@ -{{ $varName := .Name | ToVariableName | ReplaceIfNested }} +{{ $varName := .Resource.Name | ToVariableName | ReplaceIfNested }}