-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.go
56 lines (43 loc) · 1.28 KB
/
page.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
// Copyright 2018 Portal Direc's authors. All rights reserved.
//
// Authors: Rafael Campos Nunes <[email protected]>
// ... <email>
//
// Use of this source code is governed by a Apache License. The license can be
// found (LICENSE) at the root of the project.
// DOCUMENTATION
// ---------------------------------------------------------------------------
// This file is responsible for describing a web page inside Go
package main
import (
"io/ioutil"
"log"
"strings"
)
type Page struct {
Title string
Body []byte
}
var (
root string = "./html/_site/"
)
// Load a file and returns a pointer to it in case of success
func Load(title string) (*Page, error) {
body, err := ioutil.ReadFile(Filepath(title))
if err != nil {
log.Printf("Error %v", err.Error())
return nil, err
}
return &Page{Title: title, Body: body}, nil
}
// Returns the file path of a given file name, asset or html.
func Filepath(filename string) string {
split := strings.Split(filename, ".")
// The file isn't an HTML and probably is an asset because of the way that
// HTML files are loaded, they are requested without its file extension.
if len(split) > 1 {
log.Printf("Asset to load %s", filename)
return root + filename[1:]
}
return root + filename + ".html"
}