diff --git a/go/blog/Makefile b/go/blog/Makefile new file mode 100644 index 0000000..e2836e9 --- /dev/null +++ b/go/blog/Makefile @@ -0,0 +1,11 @@ +# Makefile for more convenient hugo setup + + +all: build + +build: + -mkdir dist + cd hugo && hugo -d ../dist + +clean: + rm -rf dist diff --git a/go/blog/README.md b/go/blog/README.md new file mode 100644 index 0000000..edffa3b --- /dev/null +++ b/go/blog/README.md @@ -0,0 +1,72 @@ +# Welcome to Blog Function in Go! + +This template serves as an example of how to use [Hugo](https://gohugo.io/) +package as a static file generator for your website. It uses instanced Function +in go for the deployment. All the hugo content can be found in the `hugo/` +directory. + +## How to use +The root directory will contain your standard Function with one addition - +`hugo/` directory. +This will contain all the hugo files needed. You will need to familiarize +yourself with [Hugo](https://gohugo.io/) in order to use it. + +You can develop in a live server where changes happen instanteniously with hugo. +You can do this via command: + +```bash +hugo server +``` + +Note: Look at different flag options in order to build all files, including +drafts etc. (`hugo server -D`) for example. + + +### Deploy your Function +Once you make your changes in the hugo files you will need to build static +files. You can achieve this via `hugo build` with target destination of `dist` +or whatever directory you choose in your `function.go`. You can do this via +the +following: + +```bash +hugo build --destination ../dist +``` + +Now you can simply `func run` or `func deploy` with the host builder to either +expose your Function locally or on your cluster respectively. + +Example of these commands (note that host builder is hidden behind a flag, you +need to enable +it first - this will become the default builder in the future) +```bash +export FUNC_ENABLE_HOST_BUILDER=1 +func run --container=false --builder=host +``` +Note: We are running without a container because the host builder builds on the +OS system +without a docker containarization app (func bundles up your Function in a +specific way as an archive file to make it into an image). + +```bash +export FUNC_ENABLE_HOST_BUILDER=1 +func deploy --builder=host +``` + +#### Convenient Makefile +A Makefile exists for your convenience! It has 2 simple targets - `build` and +`clean`. Once you've edited all hugo files to your liking, use `make build` to +generate the static files in the `dist` directory -- this takes care of the hugo +build step covered previously. The `clean` target is for cleaning out your files +from the `dist` directory in case you would need it. + +### Cleanup +Use `make clean` once you want to get rid of all the generated files to have a +clean Functions root directory. + +## GLHF! +- Found a mistake in the templates? +- Created a new project with Functions? + +Share it with us on +[CNCF Slack](https://cloud-native.slack.com/archives/C04LKEZUXEE)! diff --git a/go/blog/function.go b/go/blog/function.go new file mode 100644 index 0000000..d707220 --- /dev/null +++ b/go/blog/function.go @@ -0,0 +1,17 @@ +package function + +import ( + "net/http" +) + +type Function struct { + fileserver http.Handler +} + +func New() *Function { + return &Function{fileserver: http.FileServer(http.Dir("./dist"))} +} + +func (f *Function) Handle(w http.ResponseWriter, r *http.Request) { + f.fileserver.ServeHTTP(w, r) +} diff --git a/go/blog/function_test.go b/go/blog/function_test.go new file mode 100644 index 0000000..c26cd34 --- /dev/null +++ b/go/blog/function_test.go @@ -0,0 +1,25 @@ +package function + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +// TestHandle ensures that Handle executes without error and returns the +// HTTP 200 status code indicating no errors. +func TestHandle(t *testing.T) { + var ( + f = New() + w = httptest.NewRecorder() + req = httptest.NewRequest("GET", "http://example.com/test", nil) + res *http.Response + ) + f.Handle(w, req) + res = w.Result() + defer res.Body.Close() + + if res.StatusCode != 200 { + t.Fatalf("unexpected response code: %v", res.StatusCode) + } +} diff --git a/go/blog/go.mod b/go/blog/go.mod new file mode 100644 index 0000000..4f3f844 --- /dev/null +++ b/go/blog/go.mod @@ -0,0 +1,3 @@ +module function + +go 1.21 diff --git a/go/blog/hugo/.hugo_build.lock b/go/blog/hugo/.hugo_build.lock new file mode 100644 index 0000000..e69de29 diff --git a/go/blog/hugo/archetypes/default.md b/go/blog/hugo/archetypes/default.md new file mode 100644 index 0000000..25b6752 --- /dev/null +++ b/go/blog/hugo/archetypes/default.md @@ -0,0 +1,5 @@ ++++ +date = '{{ .Date }}' +draft = true +title = '{{ replace .File.ContentBaseName "-" " " | title }}' ++++ diff --git a/go/blog/hugo/assets/assets/css/main.css b/go/blog/hugo/assets/assets/css/main.css new file mode 100644 index 0000000..9cde91a --- /dev/null +++ b/go/blog/hugo/assets/assets/css/main.css @@ -0,0 +1,245 @@ +@import url('https://fonts.googleapis.com/css2?family=Literata:ital,opsz,wght@0,7..72,200..900;1,7..72,200..900&display=swap'); +@import url('https://fonts.googleapis.com/css2?family=Red+Hat+Mono:ital,wght@0,300..700;1,300..700&display=swap'); + +body { + background-color: var(--bg-color) !important; +} + +body, main { + height: 100%; + font-family: 'Literata', serif !important; + font-optical-sizing: auto; + font-style: normal; + font-size: .95em; + font-weight: normal; +} + +::selection { + background: var(--secondary); + color: black; +} + +.splash-screen { + height: 100%; +} + +nav a, a { + text-decoration: none !important; +} + +nav a:hover, a:hover { + text-decoration: underline !important; +} + +a { + font-weight: 600; + color: var(--primary-variant) !important; +} + +a:hover { + color: var(--primary) !important; +} + +@media (min-width: 1200px) { + .container { + max-width: 720px !important; + } +} + +table:not(.gist-data *) { + border-collapse: collapse; + margin-top: 1.5rem; + margin-bottom: 1.5rem; +} + +@media (min-width: 1200px) { + table:not(.gist-data *) { + width: 100%; + } +} + +th:not(.gist-data *), +td:not(.gist-data *) { + padding: .5rem; + text-align: left; +} + +th:not(.gist-data *) { + font-weight: bold; + background-color: var(--bg-variant); +} + +td:not(.gist-data *) { + border-bottom: 2px solid var(--bg-variant) !important; +} + +ul > li:has(input[type=checkbox]) { + list-style-type: none; +} + +code { + font-family: 'Red Hat Mono', serif !important; +} + +code:not(.highlight *) { + color: var(--secondary); + font-weight: 600; + user-select: all; +} + +.highlight > div { + padding: 0 1em; +} + +.highlight > pre { + padding: 1em; +} + +mark { + background-color: var(--primary-variant) !important; +} + +kbd { + background-color: var(--bg-variant) !important; + font-family: 'Red Hat Mono', monospace !important; + font-weight: bold; +} + +.post article h1, +.post article h2, +.post article h3, +.post article h4, +.post article h5, +.post article h6 { + font-size: 1.2rem; + margin: 24px 0 10px 0; + font-weight: bold; +} + +.post article h1::before { + content: "# "; + color: var(--secondary); +} + +.post article h2::before { + content: "## "; + color: var(--secondary); +} + +.post article h3::before { + content: "### "; + color: var(--secondary); +} + +.post article h4::before { + content: "#### "; + color: var(--secondary); +} + +.post article h5::before { + content: "###### "; + color: var(--secondary); +} + +.post article h6::before { + content: "###### "; + color: var(--secondary); +} + +.breadcrumb-item+.breadcrumb-item::before { + color: #6c757d !important; +} + +.tags a:hover { + background-color: var(--primary) !important; + color: #fff !important; + text-decoration: none !important; +} + +.underline { + background-image: linear-gradient(to right, var(--secondary), var(--secondary)); + background-position: bottom left; + background-repeat: no-repeat; + background-size: 100% 2px; + text-decoration: none !important; +} + +figure { + box-sizing: border-box; + display: inline-block; + max-width: 100%; + width: 100%; + text-align: center; +} + +figure img { + max-height: 500px; + max-width: 100%; + margin: 0 auto 0 auto; +} + +figure h4 { + margin-bottom: 1em; + font-size: 0.85rem !important; + font-weight: lighter !important; + position: relative; + overflow: hidden; + opacity: 0.9; +} + +figure h4::before { + content: '' !important; +} + +/* Cool blockquote style from catalinred */ +blockquote { + padding-left: 3rem !important; + position: relative; + overflow: hidden; + + &::before, + &::after{ + position: absolute; + color: #777; + } + + &::before { + content: url("data:image/svg+xml,"); + left: 15px; + } + + &::after { + content: ""; + left: 20px; + top: 25px; + width: 1px; + height: 100%; + background-color: currentColor; + } + + p { + margin: 0; + } + + p + p { + margin-top: 1rem; + } +} + +.twitter-tweet, .instagram-media { + margin-right: auto !important; + margin-left: auto !important; +} + +.post-summary { + margin: 0; +} + +ul:has(input[type=checkbox]) { + margin-left: 0 !important; + padding-left: 0.5rem !important; +} + +li > input[type=checkbox] { + margin-right: 0.2rem; +} diff --git a/go/blog/hugo/assets/assets/css/palette/catpuccin.css b/go/blog/hugo/assets/assets/css/palette/catpuccin.css new file mode 100644 index 0000000..cb90ff6 --- /dev/null +++ b/go/blog/hugo/assets/assets/css/palette/catpuccin.css @@ -0,0 +1,15 @@ +:root { + --bg-color: #e6e9ef; + --bg-variant: #dce0e8; + --primary: #1e66f5; + --primary-variant: #04a5e5; + --secondary: #e64553; +} + +.dark { + --bg-color: #1e1e2e; + --bg-variant: #181825; + --primary: #cba6f7; + --primary-variant: #f5bde6; + --secondary: #89b4fa; +} \ No newline at end of file diff --git a/go/blog/hugo/assets/assets/css/palette/default.css b/go/blog/hugo/assets/assets/css/palette/default.css new file mode 100644 index 0000000..c3c97bc --- /dev/null +++ b/go/blog/hugo/assets/assets/css/palette/default.css @@ -0,0 +1,15 @@ +:root { + --bg-color: #e6e9ef; + --bg-variant: #dce0e8; + --primary: #ff2340; + --primary-variant: #ff405a; + --secondary: #04a5e5; +} + +.dark { + --bg-color: #1E201E; + --bg-variant: #060606; + --primary: #FF5D73; + --primary-variant: #ff475f; + --secondary: #f7f5dd; +} \ No newline at end of file diff --git a/go/blog/hugo/assets/assets/css/palette/dracula.css b/go/blog/hugo/assets/assets/css/palette/dracula.css new file mode 100644 index 0000000..cdd741a --- /dev/null +++ b/go/blog/hugo/assets/assets/css/palette/dracula.css @@ -0,0 +1,15 @@ +:root { + --bg-color: #F8F8F2; + --bg-variant: #e2e2da; + --primary: #FF5555; + --primary-variant: #ff1717; + --secondary: #6272A4; +} + +.dark { + --bg-color: #282A36; + --bg-variant: #44475A; + --primary: #FFB86C; + --primary-variant: #F1FA8C; + --secondary: #50FA7B; +} \ No newline at end of file diff --git a/go/blog/hugo/assets/assets/js/main.js b/go/blog/hugo/assets/assets/js/main.js new file mode 100644 index 0000000..0f82cd2 --- /dev/null +++ b/go/blog/hugo/assets/assets/js/main.js @@ -0,0 +1 @@ +console.log('👋🏻 hello from Hugo and imgios!'); \ No newline at end of file diff --git a/go/blog/hugo/content/_index.md b/go/blog/hugo/content/_index.md new file mode 100644 index 0000000..cf827c8 --- /dev/null +++ b/go/blog/hugo/content/_index.md @@ -0,0 +1,8 @@ +--- +lead: "Basic, simple and minimal Blog as a Knative Function!" +--- + +This is a basic Functions blog site, an example which is also practical! You can check latest +updates happening in Knative Functions in post in [posts](./posts/). + +Check the [about page](./about) to learn more. diff --git a/go/blog/hugo/content/about/_index.md b/go/blog/hugo/content/about/_index.md new file mode 100644 index 0000000..3d00d84 --- /dev/null +++ b/go/blog/hugo/content/about/_index.md @@ -0,0 +1,12 @@ ++++ +title = 'About' +date = 2025-03-13T11:30:04+01:00 +draft = false ++++ + +# Welcome to the first Functions Blog! + + +This site is generated into static files by Hugo and those are simply run in a Knative Function! (Built by the new and improved Host Builder). + +You can find Func repo from the [GitHub repository](https://github.com/knative/func). diff --git a/go/blog/hugo/content/posts/hust-builder.md b/go/blog/hugo/content/posts/hust-builder.md new file mode 100644 index 0000000..2901277 --- /dev/null +++ b/go/blog/hugo/content/posts/hust-builder.md @@ -0,0 +1,33 @@ +--- +title: "The new and improved Host Builder" +description: Introduction of the Host Builder +date: 2025-03-13 +keywords: ["gohugo", "hugo", "go", "blog"] +tags: ["hugo", "themes"] +summary: This post explains what the new Host Builder is and why its our new default +--- + +## The Host Builder +We have introduced the Host Builder (currently in active developement) some months +ago and its already been available behind a flag *FUNC_ENABLE_HOST_BUILDER* which +needs to be set to truthy value in order to use it. + +# Why use it? +It's way faster to build your Functions!. Func will package your Functions +directory as an archive in a specific way into an image ready to be 'run' +locally on your machine, within seconds! + +## Building example + +{{< details summary="with time" >}} +Example of a go Function build using the Host Builder +``` +❯ FUNC_ENABLE_HOST_BUILDER=1 time func build --builder=host +Building function image + f.linux.amd64 + f.linux.arm64 + f.linux.arm.v7 +🙌 Function built: quay.io/dfridric/random:latest +1.64user 0.67system 0:01.52elapsed +``` +{{< /details >}} diff --git a/go/blog/hugo/hugo.toml b/go/blog/hugo/hugo.toml new file mode 100644 index 0000000..4528ec0 --- /dev/null +++ b/go/blog/hugo/hugo.toml @@ -0,0 +1,49 @@ +title = "Functions Go Blog" +theme = "not-much" +languageCode = "en-us" +baseURL = "https://example.org/" +copyright = "Sample custom notice © {year}" + +[markup] + [markup.highlight] + style = 'dracula' + [markup.goldmark] + [markup.goldmark.renderer] + unsafe = true + + +[params] +theme = "dark" +palette = "catpuccin" +showThemeNotice = true +showPostsSummary = true + +# Navigation +[menu] + [[menu.main]] + identifier = "home" + name = "home" + title = "Home" + url = "/" + weight = 1 + + [[menu.main]] + identifier = "posts" + name = "posts" + title = "posts" + url = "/posts" + weight = 3 + + [[menu.main]] + identifier = "about" + name = "about" + title = "About" + url = "/about" + weight = 2 + + [[menu.main]] + identifier = "github" + name = "github" + title = "GitHub" + url = "https://github.com/knative/func" + weight = 4 diff --git a/go/blog/hugo/themes/not-much b/go/blog/hugo/themes/not-much new file mode 160000 index 0000000..a7f9676 --- /dev/null +++ b/go/blog/hugo/themes/not-much @@ -0,0 +1 @@ +Subproject commit a7f9676aff5b049bbd6bd934b302f18f9f2b4a21