From 452d86ad1af61af7475914f3afcb5dfb2945e4c7 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 12 Jul 2023 18:33:04 +0200 Subject: Added ability to put content markdown files in sub folders --- README.md | 9 +++++---- main.go | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 44d85e5..e8c468a 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ The only thing hard about this project is the spelling of its name. Some facts (will be more clear when you read the whole readme): -- You cannot nest your markdown file under `content` folder. All files must be - in the root of `content` folder. +- You can nest your markdown file under `content` folder. You can use subfolders + as well. Final URL will not be affected by putting markdown files in + subfolders. - `public` folder gets automatically created on `jbmafp --build`. - All files in `static` folder will be moved to the root of `public` folder. - When you provide `url` in your markdown files, this will create these files in @@ -25,8 +26,8 @@ Some facts (will be more clear when you read the whole readme): - Comes with a small embedded HTTP server you can invoke with `jbmafo --server` which will server contents from `public` folder. Good for testing stuff. - After you have made your site you can easily create new content with `jbmafp - --new "My new shitty title"`. This will create a new markdown file in content - folder. + --new "My new shitty title"`. This will create a new markdown file in + `content` folder. ## Install diff --git a/main.go b/main.go index 71f5f94..fecc2d8 100644 --- a/main.go +++ b/main.go @@ -144,9 +144,22 @@ func buildProject(projectRoot string) { } // Gets the list of all markdown files. - files, err := filepath.Glob(path.Join(projectRoot, "content/*.md")) + var files []string + err = filepath.Walk(path.Join(projectRoot, "content/"), func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() && strings.ToLower(filepath.Ext(path)) == ".md" { + files = append(files, path) + } + + return nil + }) + if err != nil { - panic(err) + fmt.Printf("No markdown files found with error `%s`.\n", err) + os.Exit(1) } md := goldmark.New( -- cgit v1.2.3