diff --git a/README.md b/README.md index 48bc145..4708607 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,24 @@ Contributions to the scriggo.com site are greatly appreciated, as new documentat * if you find an issue on the site, [open an issue](https://github.com/open2b/scriggo/issues/new) on Scriggo. * if you want to write new documentation, as "Switch from X to Scriggo", [discuss with us](https://github.com/open2b/scriggo/discussions) and after it is approved open a PR on this repository. * if you use Scriggo at work, let us know. + ### Running the website The scriggo.com site is a Scriggo template. You can use the [scriggo command](https://scriggo.com/scriggo-command) to run it locally: ``` -cd site +cd src scriggo serve ``` ### Build the website -To build the pages of the website, execute the following command in the root directory of the repository: +To build the pages of the website, execute the following commands: ``` -go run . +cd src +scriggo build -o ../public ``` -It will create a new directory named "public" with the compiled site pages. If the directory already exists, it will be deleted first. \ No newline at end of file +It will create a new directory named "public" in the root directory to contain the compiled site pages. If a directory +named "public" already exists, it will first be deleted. \ No newline at end of file diff --git a/go.mod b/go.mod deleted file mode 100644 index 08ff293..0000000 --- a/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module open2b/scriggo-site/cmd - -go 1.23 - -require ( - github.com/open2b/scriggo v0.58.0 - github.com/yuin/goldmark v1.7.4 -) - -require gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum deleted file mode 100644 index 126c41f..0000000 --- a/go.sum +++ /dev/null @@ -1,8 +0,0 @@ -github.com/open2b/scriggo v0.58.0 h1:4m+9X2Cy7J3WgCV2GTlyE86VFr0Kxpm+9lKXO/IxSEI= -github.com/open2b/scriggo v0.58.0/go.mod h1:mKU5+0FEJmpESOObPnCY8G0OzWDaSa7zwfFvi57mPG8= -github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg= -github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go deleted file mode 100644 index 1c05481..0000000 --- a/main.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2021 The Scriggo Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "fmt" - "io" - "io/fs" - "log" - "os" - "path/filepath" - "reflect" - "strings" - "time" - - "github.com/open2b/scriggo" - "github.com/open2b/scriggo/builtin" - "github.com/open2b/scriggo/native" - - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/extension" - "github.com/yuin/goldmark/parser" - "github.com/yuin/goldmark/renderer/html" -) - -func main() { - - start := time.Now() - - dstDir, err := os.MkdirTemp(".", "public-temp-*") - if err != nil { - log.Fatal(err) - } - defer func() { - err = os.RemoveAll(dstDir) - if err != nil { - log.Fatal(err) - } - }() - - md := goldmark.New( - goldmark.WithRendererOptions(html.WithUnsafe()), - goldmark.WithParserOptions(parser.WithAutoHeadingID()), - goldmark.WithExtensions(extension.GFM), - goldmark.WithExtensions(extension.Footnote)) - - buildOptions := &scriggo.BuildOptions{ - Globals: make(native.Declarations, len(globals)+1), - MarkdownConverter: func(src []byte, out io.Writer) error { - return md.Convert(src, out) - }, - } - for n, v := range globals { - buildOptions.Globals[n] = v - } - - srcFS := os.DirFS("site") - - err = fs.WalkDir(srcFS, ".", func(name string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if name[0] == '.' { - return nil - } - if d.IsDir() { - return os.MkdirAll(filepath.Join(dstDir, name), 0700) - } - ext := filepath.Ext(name) - switch ext { - case ".html": - var dir string - if p := strings.Index(name, "/"); p > 0 { - dir = name[0:p] - } - switch dir { - case "imports", "layouts", "partials": - return nil - } - fallthrough - case ".md": - fpath := strings.TrimSuffix(name, ext) - buildOptions.Globals["filepath"] = fpath - template, err := scriggo.BuildTemplate(srcFS, name, buildOptions) - if err != nil { - return err - } - name := filepath.Join(dstDir, fpath) + ".html" - fi, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, 0600) - if err != nil { - return err - } - err = template.Run(fi, nil, nil) - if err == nil { - err = fi.Close() - } - default: - src, err := srcFS.Open(name) - if err != nil { - return err - } - name := filepath.Join(dstDir, name) - err = os.MkdirAll(filepath.Dir(name), 0700) - if err != nil { - return err - } - dst, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, 0600) - if err != nil { - return err - } - _, err = io.Copy(dst, src) - if err == nil { - _ = src.Close() - err = dst.Close() - } - } - return err - }) - if err != nil { - log.Fatal(err) - } - err = os.RemoveAll("public") - if err != nil { - log.Fatal(err) - } - err = os.Rename(dstDir, "public") - if err != nil { - log.Fatal(err) - } - buildTime := time.Since(start) - _, _ = fmt.Fprintf(os.Stderr, "Public site generated in %s\n", buildTime) - return -} - -var globals = native.Declarations{ - // crypto - "hmacSHA1": builtin.HmacSHA1, - "hmacSHA256": builtin.HmacSHA256, - "sha1": builtin.Sha1, - "sha256": builtin.Sha256, - - // encoding - "base64": builtin.Base64, - "hex": builtin.Hex, - "marshalJSON": builtin.MarshalJSON, - "marshalJSONIndent": builtin.MarshalJSONIndent, - "md5": builtin.Md5, - "unmarshalJSON": builtin.UnmarshalJSON, - - // html - "htmlEscape": builtin.HtmlEscape, - - // math - "abs": builtin.Abs, - "max": builtin.Max, - "min": builtin.Min, - "pow": builtin.Pow, - - // net - "File": reflect.TypeOf((*builtin.File)(nil)).Elem(), - "FormData": reflect.TypeOf(builtin.FormData{}), - "form": (*builtin.FormData)(nil), - "queryEscape": builtin.QueryEscape, - - // regexp - "Regexp": reflect.TypeOf(builtin.Regexp{}), - "regexp": builtin.RegExp, - - // sort - "reverse": builtin.Reverse, - "sort": builtin.Sort, - - // strconv - "formatFloat": builtin.FormatFloat, - "formatInt": builtin.FormatInt, - "parseFloat": builtin.ParseFloat, - "parseInt": builtin.ParseInt, - - // strings - "abbreviate": builtin.Abbreviate, - "capitalize": builtin.Capitalize, - "capitalizeAll": builtin.CapitalizeAll, - "hasPrefix": builtin.HasPrefix, - "hasSuffix": builtin.HasSuffix, - "index": builtin.Index, - "indexAny": builtin.IndexAny, - "join": builtin.Join, - "lastIndex": builtin.LastIndex, - "replace": builtin.Replace, - "replaceAll": builtin.ReplaceAll, - "runeCount": builtin.RuneCount, - "split": builtin.Split, - "splitAfter": builtin.SplitAfter, - "splitAfterN": builtin.SplitAfterN, - "splitN": builtin.SplitN, - "sprint": builtin.Sprint, - "sprintf": builtin.Sprintf, - "toKebab": builtin.ToKebab, - "toLower": builtin.ToLower, - "toUpper": builtin.ToUpper, - "trim": builtin.Trim, - "trimLeft": builtin.TrimLeft, - "trimPrefix": builtin.TrimPrefix, - "trimRight": builtin.TrimRight, - "trimSuffix": builtin.TrimSuffix, - - // time - "Duration": reflect.TypeOf(builtin.Duration(0)), - "Hour": time.Hour, - "Microsecond": time.Microsecond, - "Millisecond": time.Millisecond, - "Minute": time.Minute, - "Nanosecond": time.Nanosecond, - "Second": time.Second, - "Time": reflect.TypeOf(builtin.Time{}), - "date": builtin.Date, - "now": builtin.Now, - "parseDuration": builtin.ParseDuration, - "parseTime": builtin.ParseTime, - "unixTime": builtin.UnixTime, -} diff --git a/site/news.md b/site/news.md index 7089634..d84b106 100644 --- a/site/news.md +++ b/site/news.md @@ -4,6 +4,15 @@ # News +## Released Scriggo v0.58.1 +December 05, 2024 + +This release adds the `build` command to Scriggo, allowing you to build an entire template from the command line. + +### Changes + +* [cmd/scriggo: add the build command to build a template](** TODO **) **TODO ** + ## Released Scriggo v0.58.0 December 04, 2024 diff --git a/site/partials/nav.html b/site/partials/nav.html index 72c5b6a..2f0e6a2 100644 --- a/site/partials/nav.html +++ b/site/partials/nav.html @@ -10,7 +10,7 @@ %%}