1 Star 0 Fork 0

zhj2232006/books

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gen_netlify_redirects.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
Krzysztof Kowalczyk 提交于 2019-10-08 17:52 . use github.com/kjk/u more
package main
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"github.com/kjk/u"
)
const (
// https://www.netlify.com/docs/headers-and-basic-auth/#custom-headers
netlifyHeaders = `
# long-lived caching
/s/*
Cache-Control: max-age=31536000
/*
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
`
)
func genNetlifyHeaders() {
path := filepath.Join("www", "_headers")
err := ioutil.WriteFile(path, []byte(netlifyHeaders), 0644)
u.Must(err)
}
// TODO: this should be in 404.html for each book
func genNetlifyRedirectsForBook(b *Book) []string {
var res []string
// catch-all redirect for all other missing pages
s := fmt.Sprintf(`/essential/%s/* /essential/%s/404.html 404`, b.Dir, b.Dir)
res = append(res, s)
//res = append(res, "")
return res
}
func genNetlifyRedirects(books []*Book) {
var a []string
for _, b := range books {
ab := genNetlifyRedirectsForBook(b)
a = append(a, ab...)
}
s := strings.Join(a, "\n")
path := filepath.Join("www", "_redirects")
err := ioutil.WriteFile(path, []byte(s), 0644)
u.Must(err)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhj2232006/books.git
git@gitee.com:zhj2232006/books.git
zhj2232006
books
books
master

搜索帮助