๐Ÿ’พ Archived View for source.community โ€บ Fuwn โ€บ space โ€บ blob โ€บ main โ€บ template.go captured on 2023-06-14 at 14:15:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2023-01-29)

โžก๏ธ Next capture (2024-02-05)

-=-=-=-=-=-=-

                                                         .
,-. ,-. . . ,-. ,-. ,-.    ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | |   |   |-'    |   | | | | | | | | | | | | | |  | |
`-' `-' `-^ '   `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
                                                             /|
                                                            `-'

Profile for Fuwn

Fuwn / space

git clone https://source.community/Fuwn/space.git

Branches

Log

Tree

/template.go (main)

โ†‘ /

blob

View raw contents of /template.go (main)

โ”€โ”€โ”€โ”€โ•ฎ
   1โ”‚ // Copyright (C) 2021-2021 Fuwn
   2โ”‚ // SPDX-License-Identifier: GPL-3.0-only
   3โ”‚ 
   4โ”‚ package main
   5โ”‚ 
   6โ”‚ import (
   7โ”‚ 	"io"
   8โ”‚ 	"text/template"
   9โ”‚ 
  10โ”‚ 	"github.com/fuwn/space/pkg/database"
  11โ”‚ 	"github.com/pitr/gig"
  12โ”‚ 	"github.com/spf13/viper"
  13โ”‚ )
  14โ”‚ 
  15โ”‚ type Template struct {
  16โ”‚ 	Templates *template.Template
  17โ”‚ }
  18โ”‚ 
  19โ”‚ type IndexTemplate struct {
  20โ”‚ 	Content string
  21โ”‚ 	Quote   string
  22โ”‚ 	Hits    int
  23โ”‚ 	// SystemInfo string
  24โ”‚ 	Copyright string
  25โ”‚ }
  26โ”‚ type ErrorTemplate struct {
  27โ”‚ 	Error     string
  28โ”‚ 	Content   string
  29โ”‚ 	Quote     string
  30โ”‚ 	Hits      int
  31โ”‚ 	Copyright string
  32โ”‚ }
  33โ”‚ 
  34โ”‚ // Lazy...
  35โ”‚ func isHitsEnabled() bool {
  36โ”‚ 	return viper.GetBool("space.hits")
  37โ”‚ }
  38โ”‚ func (_ IndexTemplate) HitsEnabled() bool {
  39โ”‚ 	return isHitsEnabled()
  40โ”‚ }
  41โ”‚ func (_ ErrorTemplate) HitsEnabled() bool {
  42โ”‚ 	return isHitsEnabled()
  43โ”‚ }
  44โ”‚ 
  45โ”‚ func (t *Template) Render(w io.Writer, name string, data interface{}, c gig.Context) error {
  46โ”‚ 	// Check if the route is present in the hits tracker, if it isn't present, add
  47โ”‚ 	// it, but either way: increment it.
  48โ”‚ 	hits := database.Get(c.Path())
  49โ”‚ 	if hits == 0 {
  50โ”‚ 		database.Create(c.Path())
  51โ”‚ 	}
  52โ”‚ 	database.Increment(c.Path())
  53โ”‚ 
  54โ”‚ 	return t.Templates.ExecuteTemplate(w, name, data)
  55โ”‚ }
โ”€โ”€โ”€โ”€โ•ฏ

ยท ยท ยท

๐Ÿก Home

FAQs

Privacy Policy

Terms & Conditions

Official Gemlog

info@source.community

ยฉ 2023 source.community