@@ -21,48 +21,6 @@ import (
2121 highlighting "github.com/yuin/goldmark-highlighting/v2"
2222)
2323
24- // Refactor TODO:
25- /*
26- 0. CI/CD
27- 1. pnpm run build 하면 build.sh 먼저 실행 및 go run .
28- 2. pnpm run build:prod 하면 build.sh 먼저 실행 및 cross-env APP_ENV=production go run .
29-
30- 1. data 처리:
31- 1. build.sh:
32- 1. unix 명령어로 public 디렉토리 초기화(없으면 생성, 있으면 초기화)
33- DOCS: public 디렉토리 자체는 이제 main.go에서 처리하지 않음(즉, 생성 및 초기화 안함)
34- 2. sass 명령어로 public/styles 디렉토리 생성 및 scss 컴파일
35- 3. esbuild 명령어로 public/js 디렉토리 생성 및 js 컴파일
36- 4. unix 명령어로 .nojekyll 파일 생성
37- 5. unix 명령어로 robots.txt 파일 복사해서 붙여넣기
38- 6. content/assets 속 모든 파일 public/assets에 붙여넣기
39- 2. main.go:
40- 1. 포스트 관련 처리
41- 1. PostsData 처리
42- - title string
43- - date string
44- - description string
45- - category []string
46- - fixed bool
47- - sourceFilePath string <- 실제 블로그가 저장된 위치
48- e.g. content/tgpl/go 정리법
49- - slug <- 그냥 가공된 PATH로 활용될 이름임
50- e.g. go-정리법
51- -> 여기에 .html, post/, public/ 붙여서 활용하기
52- 2. post.html 생성
53- href: posts/category-foo, /, about, posts
54- DOCS: href는 해당 html에 포함된 hyperlink임
55- 3. posts.html 생성
56- href: posts/category-foo, /, about, posts
57- 4. posts/category-foo.html 생성
58- href: /, about, posts
59- 2. 블로그 관련 처리
60- 1. index.html 생성
61- 2. about.html 생성
62- 2.
63-
64- */
65-
6624func main () {
6725 // Get env
6826 var appEnv string = os .Getenv ("APP_ENV" )
@@ -199,16 +157,22 @@ func main() {
199157 fmt .Printf ("error: layout/post.html - 템플릿 파싱 실패\n " )
200158 }
201159
160+ type CategoryInfo struct {
161+ Name string
162+ URL string
163+ }
164+
202165 type PostTmplData struct {
203166 IsProduction bool
204167 Title string
205168 Date string
206169 FormattedDate string
207- Category []string
208- Description string
209- Permalink string
210- Content template.HTML
211- CurrentURL string // for nav tag
170+ // Category []string
171+ Description string
172+ Permalink string
173+ Content template.HTML
174+ CurrentURL string // for nav tag
175+ Categories []CategoryInfo
212176 }
213177
214178 for _ , data := range postsData {
@@ -232,6 +196,23 @@ func main() {
232196 return
233197 }
234198
199+ var categoriesData []CategoryInfo
200+ for _ , c := range category {
201+ var linkURL string
202+ slugifiedPath := lib .SlugifyPath (c )
203+
204+ if appEnv == "production" {
205+ linkURL = filepath .ToSlash (filepath .Join ("/" , "posts" , slugifiedPath ))
206+ } else {
207+ linkURL = filepath .ToSlash (filepath .Join ("/" , "posts" , fmt .Sprintf ("%s.html" , slugifiedPath )))
208+ }
209+
210+ categoriesData = append (categoriesData , CategoryInfo {
211+ Name : c , // "Go"
212+ URL : linkURL , // "/posts/go.html"
213+ })
214+ }
215+
235216 // Post 생성
236217 sourceBytes , err := os .ReadFile (sourceFilePath )
237218 if err != nil {
@@ -268,11 +249,12 @@ func main() {
268249 Title : title ,
269250 Date : date ,
270251 FormattedDate : formattedDate ,
271- Category : category ,
272- Description : description ,
273- Permalink : permalink ,
274- Content : template .HTML (contentBuf .String ()),
275- CurrentURL : "/posts" ,
252+ // Category: category,
253+ Description : description ,
254+ Permalink : permalink ,
255+ Content : template .HTML (contentBuf .String ()),
256+ CurrentURL : "/posts" ,
257+ Categories : categoriesData ,
276258 }
277259
278260 if err := postTemplate .Execute (outputFile , postTmplData ); err != nil {
@@ -630,22 +612,34 @@ func main() {
630612
631613 var templateString string
632614 if isFixed {
633- templateString = `<li><article class="post-item"><h3 class="post-item-title"><a href="%s">[고정됨] %s</a></h3><p class="post-item-date"><time datetime="%s">%s</time></p><p class="post-item-description">%s</p></article></li>`
615+ templateString = `<li>
616+ <article class="category-item">
617+ <h3 class="category-item-title"><a href="%s">[고정됨] %s</a></h3>
618+ <p class="category-item-date"><time datetime="%s">%s</time></p>
619+ <p class="category-item-description">%s</p>
620+ </article>
621+ </li>`
634622 postListHtml .WriteString (fmt .Sprintf (templateString , permalink , title , date , formattedDate , description ))
635623 } else {
636- templateString = `<li><article class="post-item"><h3 class="post-item-title"><a href="%s">%s</a></h3><p class="post-item-date"><time datetime="%s">%s</time></p><p class="post-item-description">%s</p></article></li>`
624+ templateString = `<li>
625+ <article class="category-item">
626+ <h3 class="category-item-title"><a href="%s">%s</a></h3>
627+ <p class="category-item-date"><time datetime="%s">%s</time></p>
628+ <p class="category-item-description">%s</p>
629+ </article>
630+ </li>`
637631 postListHtml .WriteString (fmt .Sprintf (templateString , permalink , title , date , formattedDate , description ))
638632 }
639633 }
640634
641- var backLinkURL string
642- if appEnv == "production" {
643- backLinkURL = "/posts"
644- } else {
645- backLinkURL = "/posts.html"
646- }
647- backButtonHTML := fmt .Sprintf (`<li><article class="back-link"><a href="%s ">돌아가기</a></article></li>` , backLinkURL )
648- postListHtml .WriteString (backButtonHTML )
635+ // var backLinkURL string
636+ // if appEnv == "production" {
637+ // backLinkURL = "/posts"
638+ // } else {
639+ // backLinkURL = "/posts.html"
640+ // }
641+ // backButtonHTML := fmt.Sprintf(`<li><article class="back-link"><a <a href="#" onclick="history.back(); return false; ">돌아가기</a></article></li>`, backLinkURL)
642+ // postListHtml.WriteString(backButtonHTML)
649643
650644 postListHtml .WriteString ("</ul>" )
651645 postListHtml .WriteString ("</section>" )
0 commit comments