From 9c10e1b8fc2b753359f9e1d749fe332b15fc3a06 Mon Sep 17 00:00:00 2001 From: Francesco Minnocci Date: Sat, 27 Aug 2022 12:14:24 +0200 Subject: [PATCH] feat: Add guide page --- Dockerfile | 1 + _content/guide/guida-git.md | 19 +++++++++++++ _content/guide/guida-terminale.md | 31 ++++++++++++++++++++ _views/guide-base.html | 18 ++++++++++++ _views/guide.html | 33 ++++++++++++++++++++++ cmd/phc-website-server/main.go | 3 +- handler/handler.go | 47 ++++++++++++++++++++++++++----- server/fiber.go | 14 ++++++++- 8 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 _content/guide/guida-git.md create mode 100644 _content/guide/guida-terminale.md create mode 100644 _views/guide-base.html create mode 100644 _views/guide.html diff --git a/Dockerfile b/Dockerfile index 8ecaaeb..1284a5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ COPY --from=frontend-builder /_frontend/out ./_frontend/out COPY --from=backend-builder /backend/phc-website-server ./phc-website-server COPY ./_views ./_views COPY ./_content/news ./_content/news +COPY ./_content/guide ./_content/guide COPY ./_public ./_public COPY ./.env ./.env EXPOSE 8000 diff --git a/_content/guide/guida-git.md b/_content/guide/guida-git.md new file mode 100644 index 0000000..2067d7d --- /dev/null +++ b/_content/guide/guida-git.md @@ -0,0 +1,19 @@ +--- +id: guida-git +title: "Guida a Git" +tags: git +publish_date: 2022/08/27 22:00 +description: | + Vedremo come creare una repository Git per tracciare i cambiamenti di una serie di file nel tempo, e molto altro. +--- + +## A cosa serve + +## Creiamo una repository git + +Nonostante per grossi progetti sia comodo usare server Git come github.com, che essendo popolare attirerà l'attenzione di più potenziali __contributors__, per progetti personali o +di piccola scala va benissimo utilizzare un server **self-hostato**: in questo caso noi useremo il server del PHC. + +Per prima cosa, visitiamo git.phc.dm.unipi.it ed accediamo con le credenziali di + +## Comandi di base diff --git a/_content/guide/guida-terminale.md b/_content/guide/guida-terminale.md new file mode 100644 index 0000000..761969a --- /dev/null +++ b/_content/guide/guida-terminale.md @@ -0,0 +1,31 @@ +--- +id: guida-terminale +title: "Guida al Terminale" +tags: shell, zsh, vim, ssh +publish_date: 2022/08/27 22:00 +description: | + Questo articolo introduce all'uso dei comandi di base di un terminale su sistemi Unix come Linux e MacOS; parleremo inoltre di Vim, Zsh e SSH. +--- + +## 1. Shell & Terminale: differenze? + +- introduzione storica + bash + +### Le Basi + +- keybinding utili: ctrl+a/e, ctrl+c, ctrl+d +- copiare/incollare testo +- comandi di base: navigazione(cd, ls), modifica(cp, mv, rm, mkdir) +- chiedere aiuto: man, info + +### Zsh: una shell moderna e potente + +https://wiki.archlinux.org/title/Zsh + +## 2. Vim: l'Editor intramontabile +Parentesi storica, neovim, VimTutor e comandi di base(come si esce?) + +## 3. E la TTY? +Come utilizzarla, quando è utile, limitazioni(no scrollback) + +## SSH: la magia della remote shell diff --git a/_views/guide-base.html b/_views/guide-base.html new file mode 100644 index 0000000..558b7ab --- /dev/null +++ b/_views/guide-base.html @@ -0,0 +1,18 @@ +{{template "base" .}} + +{{define "title"}}{{ .Article.Title }} • Guide • PHC{{end}} + +{{define "body"}} +
+

{{ .Article.Title }}

+
+ {{ .Article.PublishDate.Format "2006/01/02" }} +
+
+ {{ range .Article.Tags }} + {{ . }} + {{ end }} +
+ {{ .ContentHTML }} +
+{{end}} diff --git a/_views/guide.html b/_views/guide.html new file mode 100644 index 0000000..c6bb5c5 --- /dev/null +++ b/_views/guide.html @@ -0,0 +1,33 @@ +{{template "base" .}} + +{{define "title"}}Guide • PHC{{end}} + +{{define "body"}} +
+

+ + Articoli +

+
+ {{ range .Articles }} +
+ +
{{ .PublishDate.Format "2006/01/02" }}
+
+

{{ .Description }}

+
+
+ {{ range .Tags }} + {{ . }} + {{ end }} +
+
+ {{ end }} +
+
+ +{{end}} diff --git a/cmd/phc-website-server/main.go b/cmd/phc-website-server/main.go index e4ed12e..82bbf35 100644 --- a/cmd/phc-website-server/main.go +++ b/cmd/phc-website-server/main.go @@ -22,7 +22,8 @@ func main() { "./_views/base.html", "./_views/partials/*.html", ), - NewsArticlesRegistry: articles.NewRegistry("./_content/news"), + NewsArticlesRegistry: articles.NewRegistry("./_content/news"), + GuideArticlesRegistry: articles.NewRegistry("./_content/guide"), ListaUtenti: &website.JsonFileListUtenti{ Path: "./utenti-poisson-2022.local.json", }, diff --git a/handler/handler.go b/handler/handler.go index 94eefb4..a007a34 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -20,11 +20,13 @@ type Service interface { HandleStoriaPage(w io.Writer, ctx Context) error HandleQueryAppunti(w io.Writer, query string, ctx Context) error HandleNewsPage(w io.Writer, ctx Context) error + HandleGuidePage(w io.Writer, ctx Context) error HandleLogin(username, password string) (*model.Session, error) HandleUser(token string) *model.User HandleRequiredUser(ctx Context) (*model.User, error) HandleProfilePage(w io.Writer, ctx Context) error - HandleArticlePage(w io.Writer, articleID string, ctx Context) error + HandleNewsArticlePage(w io.Writer, articleID string, ctx Context) error + HandleGuideArticlePage(w io.Writer, articleID string, ctx Context) error } // @@ -40,11 +42,12 @@ func (ctx Context) getUser() *model.User { // Handler holds references to abstract services for easy testing provided by every module (TODO: Make every field an interface of -Service) type DefaultHandler struct { - AuthService auth.Service - Renderer *templates.TemplateRenderer - NewsArticlesRegistry *articles.Registry - ListaUtenti website.ListaUtentiService - Storia website.StoriaService + AuthService auth.Service + Renderer *templates.TemplateRenderer + NewsArticlesRegistry *articles.Registry + GuideArticlesRegistry *articles.Registry + ListaUtenti website.ListaUtentiService + Storia website.StoriaService } func (h *DefaultHandler) HandleStaticPage(w io.Writer, view string, ctx Context) error { @@ -102,6 +105,18 @@ func (h *DefaultHandler) HandleNewsPage(w io.Writer, ctx Context) error { }) } +func (h *DefaultHandler) HandleGuidePage(w io.Writer, ctx Context) error { + articles, err := h.GuideArticlesRegistry.GetArticles() + if err != nil { + return err + } + + return h.Renderer.Render(w, "guide.html", util.Map{ + "User": ctx.getUser(), + "Articles": articles, + }) +} + func (h *DefaultHandler) HandleLogin(username, password string) (*model.Session, error) { session, err := h.AuthService.Login(username, password) if err != nil { @@ -138,7 +153,7 @@ func (h *DefaultHandler) HandleProfilePage(w io.Writer, ctx Context) error { }) } -func (h *DefaultHandler) HandleArticlePage(w io.Writer, articleID string, ctx Context) error { +func (h *DefaultHandler) HandleNewsArticlePage(w io.Writer, articleID string, ctx Context) error { article, err := h.NewsArticlesRegistry.GetArticle(articleID) if err != nil { return err @@ -155,3 +170,21 @@ func (h *DefaultHandler) HandleArticlePage(w io.Writer, articleID string, ctx Co "ContentHTML": template.HTML(html), }) } + +func (h *DefaultHandler) HandleGuideArticlePage(w io.Writer, articleID string, ctx Context) error { + article, err := h.GuideArticlesRegistry.GetArticle(articleID) + if err != nil { + return err + } + + html, err := article.Render() + if err != nil { + return err + } + + return h.Renderer.Render(w, "guide-base.html", util.Map{ + "User": ctx.getUser(), + "Article": article, + "ContentHTML": template.HTML(html), + }) +} diff --git a/server/fiber.go b/server/fiber.go index bf16f13..f111ba7 100644 --- a/server/fiber.go +++ b/server/fiber.go @@ -100,6 +100,11 @@ func routes(h handler.Service, r fiber.Router) { return h.HandleNewsPage(c, CreateContext(c)) }) + r.Get("/guide", func(c *fiber.Ctx) error { + c.Type("html") + return h.HandleGuidePage(c, CreateContext(c)) + }) + r.Post("/login", func(c *fiber.Ctx) error { var loginForm struct { Provider string `form:"provider"` @@ -147,7 +152,14 @@ func routes(h handler.Service, r fiber.Router) { articleID := c.Params("article") c.Type("html") - return h.HandleArticlePage(c, articleID, CreateContext(c)) + return h.HandleNewsArticlePage(c, articleID, CreateContext(c)) + }) + + r.Get("/guide/:article", func(c *fiber.Ctx) error { + articleID := c.Params("article") + + c.Type("html") + return h.HandleGuideArticlePage(c, articleID, CreateContext(c)) }) routesApi(h, r.Group("/api"))