Skip to content

Commit 8237297

Browse files
committed
feat: re-structure package
1 parent 693efe6 commit 8237297

File tree

12 files changed

+255
-67
lines changed

12 files changed

+255
-67
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BINARY_PATH=$(BUILD_DIR)/$(BINARY_NAME)
99
all: build
1010

1111
build:
12-
$(GO) build -o $(BINARY_PATH) ./src
12+
$(GO) build -o $(BINARY_PATH) ./cmd/j2z/
1313

1414
build-prod:
1515
bash scripts/build.sh

Session.vim

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
let SessionLoad = 1
2+
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
3+
let v:this_session=expand("<sfile>:p")
4+
silent only
5+
silent tabonly
6+
cd ~/Development/j2z
7+
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
8+
let s:wipebuf = bufnr('%')
9+
endif
10+
let s:shortmess_save = &shortmess
11+
if &shortmess =~ 'A'
12+
set shortmess=aoOA
13+
else
14+
set shortmess=aoO
15+
endif
16+
badd +1 .github/workflows/release.yml
17+
badd +60 cmd/j2z/main.go
18+
badd +144 internal/file/file.go
19+
badd +29 internal/file/fileutils.go
20+
badd +10 internal/timezone/timezone.go
21+
badd +9 internal/processor/processor.go
22+
badd +1 internal/content/content.go
23+
badd +11 internal/args/args.go
24+
badd +4 ~/.config/nvim/lua/plugins/copilot.lua
25+
argglobal
26+
%argdel
27+
$argadd ~/Development/j2z
28+
edit ~/.config/nvim/lua/plugins/copilot.lua
29+
argglobal
30+
balt internal/timezone/timezone.go
31+
setlocal keymap=
32+
setlocal noarabic
33+
setlocal autoindent
34+
setlocal nobinary
35+
setlocal breakindent
36+
setlocal breakindentopt=
37+
setlocal bufhidden=
38+
setlocal buflisted
39+
setlocal buftype=
40+
setlocal nocindent
41+
setlocal cinkeys=0{,0},0),0],:,0#,!^F,o,O,e
42+
setlocal cinoptions=
43+
setlocal cinscopedecls=public,protected,private
44+
setlocal cinwords=if,else,while,do,for,switch
45+
setlocal colorcolumn=
46+
setlocal comments=:---,:--
47+
setlocal commentstring=--\ %s
48+
setlocal complete=.,w,b,u,t
49+
setlocal completefunc=
50+
setlocal completeslash=
51+
setlocal concealcursor=
52+
setlocal conceallevel=0
53+
setlocal nocopyindent
54+
setlocal nocursorbind
55+
setlocal nocursorcolumn
56+
setlocal cursorline
57+
setlocal cursorlineopt=both
58+
setlocal define=\\<function\\|\\<local\\%(\\s\\+function\\)\\=
59+
setlocal nodiff
60+
setlocal expandtab
61+
if &filetype != 'lua'
62+
setlocal filetype=lua
63+
endif
64+
setlocal fixendofline
65+
setlocal foldcolumn=0
66+
setlocal foldenable
67+
setlocal foldexpr=0
68+
setlocal foldignore=#
69+
setlocal foldlevel=0
70+
setlocal foldmarker={{{,}}}
71+
setlocal foldmethod=manual
72+
setlocal foldminlines=1
73+
setlocal foldnestmax=20
74+
setlocal foldtext=foldtext()
75+
setlocal formatexpr=v:lua.vim.lsp.formatexpr()
76+
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
77+
setlocal formatoptions=jcroql
78+
setlocal iminsert=0
79+
setlocal imsearch=-1
80+
setlocal includeexpr=tr(v:fname,'.','/')
81+
setlocal indentexpr=nvim_treesitter#indent()
82+
setlocal indentkeys=0{,0},0),0],:,0#,!^F,o,O,e,<:>,0=},0=),0=end,0=until
83+
setlocal noinfercase
84+
setlocal iskeyword=@,48-57,_,192-255
85+
setlocal nolinebreak
86+
setlocal nolisp
87+
setlocal lispoptions=
88+
setlocal list
89+
setlocal matchpairs=(:),{:},[:]
90+
setlocal modeline
91+
setlocal modifiable
92+
setlocal nrformats=bin,hex
93+
setlocal number
94+
setlocal numberwidth=4
95+
setlocal omnifunc=v:lua.vim.lsp.omnifunc
96+
setlocal nopreserveindent
97+
setlocal nopreviewwindow
98+
setlocal quoteescape=\\
99+
setlocal noreadonly
100+
setlocal relativenumber
101+
setlocal norightleft
102+
setlocal rightleftcmd=search
103+
setlocal scrollback=-1
104+
setlocal noscrollbind
105+
setlocal shiftwidth=2
106+
setlocal signcolumn=yes
107+
setlocal smartindent
108+
setlocal nosmoothscroll
109+
setlocal softtabstop=-1
110+
setlocal nospell
111+
setlocal spellcapcheck=[.?!]\\_[\\])'\"\\t\ ]\\+
112+
setlocal spellfile=
113+
setlocal spelllang=en
114+
setlocal spelloptions=noplainbuffer
115+
setlocal statuscolumn=
116+
setlocal suffixesadd=.lua
117+
setlocal noswapfile
118+
setlocal synmaxcol=3000
119+
if &syntax != ''
120+
setlocal syntax=
121+
endif
122+
setlocal tabstop=2
123+
setlocal tagfunc=v:lua.vim.lsp.tagfunc
124+
setlocal textwidth=0
125+
setlocal undofile
126+
setlocal varsofttabstop=
127+
setlocal vartabstop=
128+
setlocal winblend=0
129+
setlocal nowinfixbuf
130+
setlocal nowinfixheight
131+
setlocal nowinfixwidth
132+
setlocal winhighlight=
133+
setlocal nowrap
134+
setlocal wrapmargin=0
135+
silent! normal! zE
136+
let &fdl = &fdl
137+
let s:l = 4 - ((3 * winheight(0) + 34) / 68)
138+
if s:l < 1 | let s:l = 1 | endif
139+
keepjumps exe s:l
140+
normal! zt
141+
keepjumps 4
142+
normal! 020|
143+
lcd ~/Development/j2z
144+
tabnext 1
145+
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
146+
silent exe 'bwipe ' . s:wipebuf
147+
endif
148+
unlet! s:wipebuf
149+
set winheight=1 winwidth=20
150+
let &shortmess = s:shortmess_save
151+
let s:sx = expand("<sfile>:p:r")."x.vim"
152+
if filereadable(s:sx)
153+
exe "source " . fnameescape(s:sx)
154+
endif
155+
let &g:so = s:so_save | let &g:siso = s:siso_save
156+
set hlsearch
157+
nohlsearch
158+
let g:this_session = v:this_session
159+
let g:this_obsession = v:this_session
160+
doautoall SessionLoadPost
161+
unlet SessionLoad
162+
" vim: set ft=vim :

src/main.go renamed to cmd/j2z/main.go

+20-27
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@ package main
22

33
import (
44
"flag"
5-
"log"
65
"os"
76
"strings"
87
"sync"
9-
"time"
10-
)
11-
12-
// struct to hold all arguments
13-
type Args struct {
14-
jekyllDir string
15-
zolaDir string
16-
taxonomies []string
17-
tz *time.Location
18-
aliases bool
19-
}
208

21-
var logger *log.Logger = log.New(os.Stdout, "j2z: ", 0)
9+
"github.com/en9inerd/j2z/internal/args"
10+
fl "github.com/en9inerd/j2z/internal/file"
11+
"github.com/en9inerd/j2z/internal/log"
12+
"github.com/en9inerd/j2z/internal/processor"
13+
"github.com/en9inerd/j2z/internal/timezone"
14+
)
2215

2316
func splitFlag(flagValue string) []string {
2417
if flagValue == "" {
@@ -39,27 +32,27 @@ func main() {
3932
flag.Parse()
4033

4134
if *versionFlag {
42-
logger.Printf("version %s\n", Version)
35+
log.Logger.Printf("version %s\n", Version)
4336
os.Exit(0)
4437
}
4538

46-
cliArgs := Args{
47-
jekyllDir: *jekyllDirFlag,
48-
zolaDir: *zolaDirFlag,
49-
taxonomies: splitFlag(*taxonomiesFlag),
50-
aliases: *alisesFlag,
51-
tz: getTimeZone(*tzNameFlag),
39+
cliArgs := args.Args{
40+
JekyllDir: *jekyllDirFlag,
41+
ZolaDir: *zolaDirFlag,
42+
Taxonomies: splitFlag(*taxonomiesFlag),
43+
Aliases: *alisesFlag,
44+
Tz: timezone.GetTimeZone(*tzNameFlag),
5245
}
5346

54-
if cliArgs.jekyllDir == "" || cliArgs.zolaDir == "" {
55-
logger.Println("Error: Both --jekyllDir and --zolaDir must be provided")
47+
if cliArgs.JekyllDir == "" || cliArgs.ZolaDir == "" {
48+
log.Logger.Println("Error: Both --jekyllDir and --zolaDir must be provided")
5649
flag.Usage() // Show usage information
5750
os.Exit(1)
5851
}
5952

60-
inputMdFiles, err := getMarkdownFiles(&cliArgs)
53+
inputMdFiles, err := fl.GetMarkdownFiles(&cliArgs)
6154
if err != nil {
62-
logger.Fatalf("Failed to get markdown files: %v", err)
55+
log.Logger.Fatalf("Failed to get markdown files: %v", err)
6356
}
6457

6558
var wg sync.WaitGroup
@@ -68,9 +61,9 @@ func main() {
6861
go func(file string) {
6962
defer wg.Done()
7063

71-
mdFile := &JekyllMarkdownFile{Path: file}
72-
if err := processMarkdownFile(mdFile, &cliArgs); err != nil {
73-
logger.Printf("Failed to process file %s: %v", file, err)
64+
mdFile := &fl.JekyllMarkdownFile{Path: file}
65+
if err := processor.ProcessMarkdownFile(mdFile, &cliArgs); err != nil {
66+
log.Logger.Printf("Failed to process file %s: %v", file, err)
7467
}
7568
}(file)
7669
}

internal/args/args.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package args
2+
3+
import "time"
4+
5+
// struct to hold all arguments
6+
type Args struct {
7+
JekyllDir string
8+
ZolaDir string
9+
Taxonomies []string
10+
Tz *time.Location
11+
Aliases bool
12+
}

src/content.go renamed to internal/content/content.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package main
1+
package content
22

33
import (
44
"fmt"
55
"regexp"
66
)
77

88
// Combines TOML front matter with markdown content
9-
func combineFrontMatterAndContent(tomlData []byte, content []byte) string {
10-
contentProcessing(&content)
9+
func CombineFrontMatterAndContent(tomlData []byte, content []byte) string {
10+
ContentProcessing(&content)
1111

1212
re := regexp.MustCompile(`(?s)---\n(.*?)\n---`)
1313
content = re.ReplaceAll(content, []byte(""))
1414

1515
return fmt.Sprintf("+++\n%s+++%s", tomlData, content)
1616
}
1717

18-
func contentProcessing(content *[]byte) {
18+
func ContentProcessing(content *[]byte) {
1919
// Correct the <!--more--> tag
2020
re := regexp.MustCompile(`(?i)<!--\s*more\s*-->`)
2121
if re.Match(*content) {

src/file.go renamed to internal/file/file.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package file
22

33
import (
44
"fmt"
@@ -9,6 +9,8 @@ import (
99
"time"
1010

1111
"github.com/BurntSushi/toml"
12+
"github.com/en9inerd/j2z/internal/args"
13+
"github.com/en9inerd/j2z/internal/content"
1214
"gopkg.in/yaml.v3"
1315
)
1416

@@ -40,8 +42,8 @@ var dateFormats = []string{
4042
type MarkdownFile interface {
4143
Load() error
4244
ProcessFrontMatter() error
43-
ConvertToTOML(args *Args) error
44-
Save(args *Args) error
45+
ConvertToTOML(args *args.Args) error
46+
Save(args *args.Args) error
4547
}
4648

4749
type JekyllMarkdownFile struct {
@@ -72,15 +74,15 @@ func (f *JekyllMarkdownFile) ProcessFrontMatter() error {
7274
return nil
7375
}
7476

75-
func (f *JekyllMarkdownFile) ConvertToTOML(args *Args) error {
77+
func (f *JekyllMarkdownFile) ConvertToTOML(args *args.Args) error {
7678
var data map[string]interface{}
7779
err := yaml.Unmarshal(f.FrontMatter, &data)
7880
if err != nil {
7981
return err
8082
}
8183

8284
// Add alias if the flag is set
83-
if args.aliases {
85+
if args.Aliases {
8486
fileName := path.Base(f.Path)
8587

8688
re := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})-(.*)\.md`)
@@ -100,7 +102,7 @@ func (f *JekyllMarkdownFile) ConvertToTOML(args *Args) error {
100102
var err error
101103

102104
for _, format := range dateFormats {
103-
if t, err = time.ParseInLocation(format, dateStr, args.tz); err == nil {
105+
if t, err = time.ParseInLocation(format, dateStr, args.Tz); err == nil {
104106
data["date"] = t
105107
break
106108
}
@@ -121,7 +123,7 @@ func (f *JekyllMarkdownFile) ConvertToTOML(args *Args) error {
121123
taxonomies := make(map[string]interface{})
122124
for key, value := range data {
123125
// Check if key is taxonomy
124-
if slices.Contains(args.taxonomies, key) {
126+
if slices.Contains(args.Taxonomies, key) {
125127
taxonomies[key] = value
126128
delete(data, key) // Remove the taxonomy key from the original map
127129
continue
@@ -157,12 +159,12 @@ func (f *JekyllMarkdownFile) ConvertToTOML(args *Args) error {
157159
return nil
158160
}
159161

160-
func (f *JekyllMarkdownFile) Save(args *Args) error {
161-
outputFilePath, outputDirPath, err := getOutputPaths(f.Path, &args.jekyllDir, &args.zolaDir)
162+
func (f *JekyllMarkdownFile) Save(args *args.Args) error {
163+
outputFilePath, outputDirPath, err := getOutputPaths(f.Path, &args.JekyllDir, &args.ZolaDir)
162164
if err != nil {
163165
return err
164166
}
165-
combined := combineFrontMatterAndContent(f.FrontMatter, f.Content)
167+
combined := content.CombineFrontMatterAndContent(f.FrontMatter, f.Content)
166168

167169
if _, err := os.Stat(outputDirPath); os.IsNotExist(err) {
168170
err := os.MkdirAll(outputDirPath, 0755)

0 commit comments

Comments
 (0)