Skip to content
Permalink
Browse files

Refactor entire code base, remove unit tests

Removed unit tests, I intend on replacing these with functionality
tests. These will most likely be a collection of shell scripts that will build,
and then run the program.

The main config file is now less bloated. Index layouts are managed at
the filesystem level, instead of being all shoved into the main config
file. So when defining a layout for an index of posts simply place your
layouts inside an '_index' directory, for example:

  programming/_index/
  programming/_index/all
  programming/_index/day
  programming/_index/month
  programming/_index/year

The above example is how you would define day, month, year, and all
indexes for the 'programming' category. If these files are found during
the publishing stage then they will be used to create the index of posts
for the journal.

Multiple remotes have been scrapped completely, in favour of a single
remote per journal. In my opinion this is simpler, and as far as I can
see there would be no reason for a single journal to have multiple
remotes.

Syntax highlighting for code blocks in pages, and posts is now handled
by the new 'gen-style' command. This will take the name of the style you
wish to apply to the blocks of code, and write the CSS of that style to
'stdout'. So if you would like to have syntax highlighting for your code
blocks simply do the following:

  $ jrnl gen-style solarized-light > _site/assets/style.css

Of course you would then include a link tag to the newly created
'style.css' file to your layout files where appropriate.

Other things of note, the `_meta.yml` file has been renamed to 'config'.
I find the name better encapsulates its purpose. And the 'command'
package has been renamed to 'cmd', just because I prefer 'cmd' over
'command'.

The 'usage' package has also been removed, this is only temporary.
  • Loading branch information...
Andrew Pillar
Andrew Pillar committed Jan 21, 2019
1 parent a2c2d27 commit f8aaa246fe4480129650c5a8817b3ad4780cf3bf
Showing with 1,687 additions and 3,692 deletions.
  1. +41 −37 category/category.go
  2. +0 −64 category/category_test.go
  3. 0 category/testdata/.gitkeep
  4. 0 category/testdata/_posts/.gitkeep
  5. 0 category/testdata/_posts/category-one/.gitkeep
  6. 0 category/testdata/_posts/category-one/category-two/.gitkeep
  7. 0 category/testdata/_posts/category/.gitkeep
  8. +52 −0 cmd/edit.go
  9. +28 −0 cmd/genstyle.go
  10. +32 −0 cmd/init.go
  11. +7 −4 {command → cmd}/ls.go
  12. +49 −0 cmd/page.go
  13. +32 −0 cmd/post.go
  14. +346 −0 cmd/publish.go
  15. +36 −0 cmd/remote-set.go
  16. +53 −0 cmd/rm.go
  17. +155 −0 cmd/theme.go
  18. +32 −0 cmd/title.go
  19. +0 −58 command/edit.go
  20. +0 −65 command/init.go
  21. +0 −80 command/page.go
  22. +0 −7 command/post.go
  23. +0 −620 command/publish.go
  24. +0 −158 command/remote.go
  25. +0 −52 command/rm.go
  26. +0 −137 command/theme.go
  27. +0 −38 command/title.go
  28. +122 −0 config/config.go
  29. +6 −8 go.mod
  30. +25 −22 go.sum
  31. +213 −0 index/index.go
  32. +18 −75 main.go
  33. +0 −128 meta/meta.go
  34. +0 −60 meta/meta_test.go
  35. +69 −75 page/page.go
  36. +0 −111 page/page_test.go
  37. +0 −9 page/testdata/_pages/page.md
  38. +0 −5 page/testdata/page.golden
  39. +0 −5 page/testdata/page_plain.golden
  40. +75 −133 post/post.go
  41. +0 −173 post/post_test.go
  42. +0 −12 post/testdata/_posts/category-one/category-two/post.md
  43. +0 −12 post/testdata/_posts/category-one/post.md
  44. +0 −12 post/testdata/_posts/post.md
  45. +0 −5 post/testdata/body.golden
  46. +0 −5 post/testdata/body_plain.golden
  47. +0 −1 post/testdata/preview.golden
  48. +0 −1 post/testdata/preview_plain.golden
  49. +0 −318 readme.md
  50. +14 −36 render/render.go
  51. +12 −0 site/site.go
  52. +6 −29 template/template.go
  53. +0 −167 template/template_test.go
  54. +0 −10 template/testdata/_layouts/page
  55. +0 −3 template/testdata/_layouts/partial
  56. +0 −10 template/testdata/_layouts/post
  57. +0 −9 template/testdata/_pages/page.md
  58. +0 −12 template/testdata/_posts/post.md
  59. +0 −1 template/testdata/categories.golden
  60. +0 −15 template/testdata/page.golden
  61. +0 −5 template/testdata/partial.golden
  62. +0 −15 template/testdata/post.golden
  63. +0 −114 theme/tar.go
  64. 0 theme/testdata/_layouts/post
  65. +0 −16 theme/testdata/_meta.yml
  66. 0 theme/testdata/_site/assets/main.css
  67. 0 theme/testdata/_themes/.gitkeep
  68. +150 −71 theme/theme.go
  69. +0 −42 theme/theme_test.go
  70. +0 −11 usage/edit.go
  71. +0 −11 usage/init.go
  72. +0 −14 usage/ls.go
  73. +0 −11 usage/page.go
  74. +0 −13 usage/post.go
  75. +0 −14 usage/publish.go
  76. +0 −57 usage/remote.go
  77. +0 −11 usage/rm.go
  78. +0 −62 usage/theme.go
  79. +0 −11 usage/title.go
  80. +0 −48 usage/usage.go
  81. +0 −148 util/copy.go
  82. 0 util/testdata/copy/src/file
  83. +0 −1 util/testdata/dir/file
  84. +0 −7 util/testdata/front-matter.input
  85. 0 util/testdata/root/.gitkeep
  86. +114 −110 util/util.go
  87. +0 −118 util/util_test.go
@@ -7,44 +7,16 @@ import (
"path/filepath"
"strings"

"github.com/andrewpillar/jrnl/meta"
"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/util"
)

type Category struct {
ID string
Name string

ID string
Name string
Categories []Category
}

func Find(id string) (Category, error) {
sourcePath := filepath.Join(meta.PostsDir, id)

_, err := os.Stat(sourcePath)

if err != nil {
return Category{}, err
}

parts := strings.Split(util.Deslug(id), string(os.PathSeparator))
name := bytes.Buffer{}

for i, p := range parts {
name.WriteString(util.Title(p))

if i != len(parts) - 1 {
name.WriteString(" / ")
}
}

return Category{
ID: id,
Name: name.String(),
Categories: make([]Category, 0),
}, nil
}

func All() ([]Category, error) {
categories := make(map[string]*Category)

@@ -53,11 +25,11 @@ func All() ([]Category, error) {
return err
}

if path == meta.PostsDir || !info.IsDir() {
if path == config.PostsDir || !info.IsDir() || strings.Contains(path, config.IndexDir) {
return nil
}

id := strings.Replace(path, meta.PostsDir + string(os.PathSeparator), "", 1)
id := strings.Replace(path, config.PostsDir + string(os.PathSeparator), "", 1)
parts := strings.Split(id, string(os.PathSeparator))

c, err := Find(id)
@@ -76,16 +48,14 @@ func All() ([]Category, error) {
}

parent.Categories = append(parent.Categories, c)

return nil
}

categories[id] = &c

return nil
}

err := filepath.Walk(meta.PostsDir, walk)
err := filepath.Walk(config.PostsDir, walk)

ret := make([]Category, len(categories), len(categories))
i := 0
@@ -98,6 +68,40 @@ func All() ([]Category, error) {
return ret, err
}

func Find(id string) (Category, error) {
path := filepath.Join(config.PostsDir, id)

_, err := os.Stat(path)

if err != nil {
return Category{}, err
}

parts := strings.Split(util.Deslug(id), string(os.PathSeparator))
name := bytes.Buffer{}
end := len(parts) - 1

for i, p := range parts {
name.WriteString(strings.Title(p))

if i != end {
name.WriteString(" / ")
}
}

return Category{
ID: id,
Name: name.String(),
Categories: make([]Category, 0),
}, nil
}

func (c Category) Href() string {
return "/" + c.ID
return ""
}

func (c Category) IsZero() bool {
return c.ID == "" &&
c.Name == "" &&
len(c.Categories) == 0
}

This file was deleted.

No changes.
No changes.
No changes.
No changes.
No changes.
@@ -0,0 +1,52 @@
package cmd

import (
"errors"
"os"

"github.com/andrewpillar/cli"

"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/page"
"github.com/andrewpillar/jrnl/post"
"github.com/andrewpillar/jrnl/util"
)

func Edit(c cli.Command) {
if err := config.Initialized(""); err != nil {
util.ExitError("not initialized", err)
}

id := c.Args.Get(0)

if id == "" {
util.ExitError("failed to edit entry", errors.New("missing id"))
}

pg, err := page.Find(id)

if err == nil {
if err := pg.Touch(); err != nil {
util.ExitError("failed to edit page", err)
}

util.OpenInEditor(pg.SourcePath)
return
}

if !os.IsNotExist(err) {
util.ExitError("failed to edit page", err)
}

pt, err := post.Find(id)

if err != nil {
util.ExitError("failed to edit post", err)
}

if err := pt.Touch(); err != nil {
util.ExitError("failed to edit post", err)
}

util.OpenInEditor(pt.SourcePath)
}
@@ -0,0 +1,28 @@
package cmd

import (
"os"

"github.com/alecthomas/chroma/styles"

"github.com/andrewpillar/cli"

"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/render"
"github.com/andrewpillar/jrnl/util"
)

func GenStyle(c cli.Command) {
if err := config.Initialized(""); err != nil {
util.ExitError("not initialized", err)
}

style := styles.Get(c.Args.Get(0))

if style == nil {
style = styles.Fallback
}

r := render.New()
r.Formatter.WriteCSS(os.Stdout, style)
}
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

"github.com/andrewpillar/cli"

"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/util"
)

func Init(c cli.Command) {
target := c.Args.Get(0)

if err := config.Initialized(target); err == nil {
util.ExitError("journal already initialized", nil)
}

for _, dir := range config.Dirs {
if err := os.MkdirAll(filepath.Join(target, dir), config.DirMode); err != nil {
util.ExitError("failed to initialize", err)
}
}

if err := config.Create(target); err != nil {
util.ExitError("failed to initialize", err)
}

fmt.Println("journal initialized, set the title with 'jrnl title'")
}
@@ -1,29 +1,32 @@
package command
package cmd

import (
"fmt"
"strings"

"github.com/andrewpillar/cli"

"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/page"
"github.com/andrewpillar/jrnl/post"
"github.com/andrewpillar/jrnl/util"
)

func Ls(c cli.Command) {
util.MustBeInitialized()
if err := config.Initialized(""); err != nil {
util.ExitError("not initialized", err)
}

pages, err := page.All()

if err != nil {
util.Exit("failed to get all pages", err)
util.ExitError("failed to get all pages", err)
}

posts, err := post.All()

if err != nil {
util.Exit("failed to get all posts", err)
util.ExitError("failed to get all posts", err)
}

for _, p := range pages {
@@ -0,0 +1,49 @@
package cmd

import (
"errors"
"fmt"

"github.com/andrewpillar/cli"

"github.com/andrewpillar/jrnl/config"
"github.com/andrewpillar/jrnl/page"
"github.com/andrewpillar/jrnl/util"
)

func createPage(title string) (*page.Page, error) {
if title == "" {
return nil, errors.New("missing title")
}

cfg, err := config.Open()

if err != nil {
return nil, err
}

defer cfg.Close()

p := page.New(title)

return p, nil
}

func Page(c cli.Command) {
if err := config.Initialized(""); err != nil {
util.ExitError("not initialized", err)
}

p, err := createPage(c.Args.Get(0))

if err != nil {
util.ExitError("failed to create page", err)
}

if err := p.Touch(); err != nil {
util.ExitError("failed to create page", err)
}

util.OpenInEditor(p.SourcePath)
fmt.Println("new page added", p.ID)
}

0 comments on commit f8aaa24

Please sign in to comment.
You can’t perform that action at this time.