-
Notifications
You must be signed in to change notification settings - Fork 167
/
scommon.go
118 lines (97 loc) · 3.32 KB
/
scommon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package scommon
import (
"fmt"
"html/template"
"os"
"path/filepath"
"strings"
"github.com/brandur/modulir/modules/mtemplate"
"github.com/brandur/modulir/modules/mtemplatemd"
"github.com/brandur/sorg/modules/stemplate"
)
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Constants
//
//
//
//////////////////////////////////////////////////////////////////////////////
const (
// AtomAuthorName is the name of the author to include in Atom feeds.
AtomAuthorName = "Brandur Leach"
// AtomTag is a stable constant to use in Atom tags.
AtomTag = "brandur.org"
// DataDir is where various TOML files for quantified self statistics
// reside. These are pulled from another project which updates them
// automatically.
DataDir = "./data"
// LayoutsDir is the source directory for view layouts.
LayoutsDir = "./layouts"
// MainLayout is the site's main layout in the deprecated ACE templating
// system. This is no longer used except in a few near retired pages like
// runs and Twitter.
MainLayout = LayoutsDir + "/main.ace"
// NanoglyphsLayout is the layout for a Nanoglyph issue (an email
// newsletter).
NanoglyphsLayout = LayoutsDir + "/nanoglyphs.ace"
// PassagesLayout is the layout for a Passages & Glass issue (an email
// newsletter).
PassagesLayout = LayoutsDir + "/passages.ace"
// TempDir is a temporary directory used to download images that will be
// processed and such.
TempDir = "./tmp"
// TitleSuffix is the suffix to add to the end of page and Atom titles.
TitleSuffix = " — brandur.org"
// ViewsDir is the source directory for views.
ViewsDir = "./views"
)
// TwitterInfo is some HTML that includes a Twitter link which can be appended
// to the publishing info of various content.
const TwitterInfo = template.HTML(`<p>Find me on Twitter at ` +
`<strong><a href="https://twitter.com/brandur">@brandur</a></strong>.</p>`)
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Variables
//
//
//
//////////////////////////////////////////////////////////////////////////////
// HTMLTemplateFuncMap is a function map of template helpers which is the
// combined version of the maps from ftemplate, mtemplate, and mtemplatemd.
var HTMLTemplateFuncMap = mtemplate.CombineFuncMaps(
stemplate.FuncMap,
mtemplate.FuncMap,
mtemplatemd.FuncMap,
)
// TextTemplateFuncMap is a combined set of template helpers for text
// templates.
var TextTemplateFuncMap = mtemplate.HTMLFuncMapToText(HTMLTemplateFuncMap)
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Functions
//
//
//
//////////////////////////////////////////////////////////////////////////////
// ExitWithError prints the given error to stderr and exits with a status of 1.
func ExitWithError(err error) {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
// ExtractSlug gets a slug for the given filename by using its basename
// stripped of file extension.
func ExtractSlug(source string) string {
return strings.TrimSuffix(filepath.Base(source), filepath.Ext(source))
}
// IsDraft does really simplistic detection on whether the given source is a
// draft by looking whether the name "drafts" is in its parent directory's
// name.
func IsDraft(source string) bool {
return strings.Contains(filepath.Base(filepath.Dir(source)), "drafts")
}