From 4545102bc86270c2117d56e385c49ca526f1eb86 Mon Sep 17 00:00:00 2001 From: Anirudh Sudhir Date: Sun, 7 Apr 2024 13:26:06 +0530 Subject: [PATCH] feat: re-enable html validation and minor fixes --- README.md | 16 ++++--- ...validate_html.go.temp => validate_html.go} | 5 ++- go.mod | 5 ++- go.sum | 43 ++++++++++++++++++- main.go | 16 ++++--- pkg/engine/user_engine.go | 8 +++- pkg/helpers/helper.go | 5 --- TODO.md => site/content/posts/TODO.md | 0 .../engine/render_user_defined/rendered/.html | 10 ----- 9 files changed, 76 insertions(+), 32 deletions(-) rename cmd/anna/{validate_html.go.temp => validate_html.go} (90%) rename TODO.md => site/content/posts/TODO.md (100%) delete mode 100644 test/engine/render_user_defined/rendered/.html diff --git a/README.md b/README.md index d6c541f..c8d119b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Inspired by [Hugo](https://gohugo.io) and [Saaru](https://github.com/anirudhRowj This project is a part of the ACM PESU-ECC's yearly [AIEP](https://acmpesuecc.github.io/aiep) program, and is maintained by [Adhesh Athrey](https://github.com/DedLad), [Nathan Paul](https://github.com/polarhive), [Anirudh Sudhir](https://github.com/anirudhsudhir), and [Aditya Hegde](https://github.com/bwaklog) --- + ## Install ```sh @@ -38,6 +39,7 @@ go run . ### Detailed documentation of our SSG can be found [here](https://anna-docs.netlify.app/) --- + ## Flags ```text @@ -45,10 +47,12 @@ Usage: anna [flags] Flags: - -a, --addr string ip address to serve rendered content to (default "8000") - -d, --draft renders draft posts - -h, --help help for anna - -p, --prof enable profiling - -s, --serve serve the rendered content - -w, --webconsole wizard to setup anna + -a, --addr string ip address to serve rendered content to (default "8000") + -d, --draft renders draft posts + -h, --help help for anna + -l, --layout validates html layouts + -p, --prof enable profiling + -s, --serve serve the rendered content + -v, --version prints current version number + -w, --webconsole wizard to setup anna ``` diff --git a/cmd/anna/validate_html.go.temp b/cmd/anna/validate_html.go similarity index 90% rename from cmd/anna/validate_html.go.temp rename to cmd/anna/validate_html.go index c9c9bfb..a1f604c 100644 --- a/cmd/anna/validate_html.go.temp +++ b/cmd/anna/validate_html.go @@ -8,10 +8,11 @@ import ( "strings" "github.com/PuerkitoBio/goquery" + "github.com/acmpesuecc/anna/pkg/helpers" ) -func ValidateHTMLContent() { - root, err := filepath.Abs(SiteDataPath + "rendered") +func (cmd *Cmd) ValidateHTMLContent() { + root, err := filepath.Abs(helpers.SiteDataPath + "rendered") if err != nil { log.Fatalf("Error getting absolute path: %v", err) } diff --git a/go.mod b/go.mod index d01c2d4..9bd964d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/acmpesuecc/anna go 1.22.0 require ( + github.com/PuerkitoBio/goquery v1.9.1 github.com/cheggaaa/pb/v3 v3.1.5 github.com/spf13/cobra v1.8.0 github.com/yuin/goldmark v1.7.0 @@ -11,6 +12,7 @@ require ( require ( github.com/VividCortex/ewma v1.2.0 // indirect + github.com/andybalholm/cascadia v1.3.2 // indirect github.com/fatih/color v1.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect @@ -20,6 +22,7 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.6.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.17.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) diff --git a/go.sum b/go.sum index 8b86ad8..8ffbff3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ +github.com/PuerkitoBio/goquery v1.9.1 h1:mTL6XjbJTZdpfL+Gwl5U2h1l9yEkJjhmlTeV9VPW7UI= +github.com/PuerkitoBio/goquery v1.9.1/go.mod h1:cW1n6TmIMDoORQU5IU/P1T3tGFunOeXEpGP2WHRwkbY= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= +github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= +github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= github.com/cheggaaa/pb/v3 v3.1.5 h1:QuuUzeM2WsAqG2gMqtzaWithDJv0i+i6UlnwSCI4QLk= github.com/cheggaaa/pb/v3 v3.1.5/go.mod h1:CrxkeghYTXi1lQBEI7jSn+3svI3cuc19haAj6jM60XI= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -33,11 +37,48 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= 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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/main.go b/main.go index 9ca151d..6ece361 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,13 @@ import ( ) func main() { - var serve bool var addr string - var webconsole bool + var prof bool var renderDrafts bool + var serve bool + var webconsole bool var version bool - var prof bool + var validateHTMLLayouts bool var Version string = "v1.0.0-alpha-15-g1eb8e48" // to be set at build time $(git describe --tags) rootCmd := &cobra.Command{ @@ -44,6 +45,10 @@ func main() { fmt.Println("Current version:", Version) } + if validateHTMLLayouts { + annaCmd.ValidateHTMLContent() + } + if webconsole { server := anna.NewWizardServer(":8080") go server.Start() @@ -56,11 +61,12 @@ func main() { }, } - rootCmd.Flags().BoolVarP(&serve, "serve", "s", false, "serve the rendered content") rootCmd.Flags().StringVarP(&addr, "addr", "a", "8000", "ip address to serve rendered content to") rootCmd.Flags().BoolVarP(&renderDrafts, "draft", "d", false, "renders draft posts") - rootCmd.Flags().BoolVarP(&version, "version", "v", false, "prints current version number") + rootCmd.Flags().BoolVarP(&validateHTMLLayouts, "layout", "l", false, "validates html layouts") rootCmd.Flags().BoolVarP(&prof, "prof", "p", false, "enable profiling") + rootCmd.Flags().BoolVarP(&serve, "serve", "s", false, "serve the rendered content") + rootCmd.Flags().BoolVarP(&version, "version", "v", false, "prints current version number") rootCmd.Flags().BoolVarP(&webconsole, "webconsole", "w", false, "wizard to setup anna") if err := rootCmd.Execute(); err != nil { diff --git a/pkg/engine/user_engine.go b/pkg/engine/user_engine.go index 4415ce1..2779ffd 100644 --- a/pkg/engine/user_engine.go +++ b/pkg/engine/user_engine.go @@ -58,6 +58,12 @@ func (e *Engine) RenderUserDefinedPages(fileOutPath string, templ *template.Temp semaphore := make(chan struct{}, concurrency) for _, templateURL := range templateURLs { + templData := e.Templates[template.URL(templateURL)] + fileInPath := strings.TrimSuffix(string(templData.CompleteURL), ".html") + if fileInPath == "" { + continue + } + wg.Add(1) semaphore <- struct{}{} @@ -67,8 +73,6 @@ func (e *Engine) RenderUserDefinedPages(fileOutPath string, templ *template.Temp wg.Done() }() - templData := e.Templates[template.URL(templateURL)] - fileInPath := strings.TrimSuffix(string(templData.CompleteURL), ".html") e.RenderPage(fileOutPath, template.URL(fileInPath), templData, templ, "page") }(templateURL) } diff --git a/pkg/helpers/helper.go b/pkg/helpers/helper.go index 10c261f..7ee8a20 100644 --- a/pkg/helpers/helper.go +++ b/pkg/helpers/helper.go @@ -69,11 +69,6 @@ func (h *Helper) CreateRenderedDir(fileOutPath string) { if err != nil { h.ErrorLogger.Fatal(err) } - - err = os.MkdirAll(fileOutPath+"rendered/layout/", 0750) - if err != nil { - h.ErrorLogger.Fatal(err) - } } func (h *Helper) Bootstrap() { diff --git a/TODO.md b/site/content/posts/TODO.md similarity index 100% rename from TODO.md rename to site/content/posts/TODO.md diff --git a/test/engine/render_user_defined/rendered/.html b/test/engine/render_user_defined/rendered/.html deleted file mode 100644 index c3dcf98..0000000 --- a/test/engine/render_user_defined/rendered/.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - -
- -
-

Index Page

- -