upgraded bootstrap, fixed style, added share blacklisting

This commit is contained in:
ston1th 2018-09-14 20:49:50 +02:00
commit 3fb1cfc17d
37 changed files with 811 additions and 892 deletions

View file

@ -1,4 +1,4 @@
// Copyright (C) 2017 Marius Schellenberger
// Copyright (C) 2018 Marius Schellenberger
package render
@ -22,8 +22,9 @@ func makeFilter() analysis.CharFilter {
}
var (
reHeader = regexp.MustCompile("(<h[1-6])>(.+)(</h[1-6]>)")
reLink = regexp.MustCompile(`id="(.+)">`)
//reHeader = regexp.MustCompile("(<h[1-6])>(.+)(</h[1-6]>)")
reHeader = regexp.MustCompile("(<h[1-6]>)(.+)(</h[1-6]>)")
reLink = regexp.MustCompile(`id="(.+?)"`)
whiteSpace = regexp.MustCompile(`\s+`)
reIndex = regexp.MustCompile("<h([1-6])>(.+)</h[1-6]>")
titleRe = regexp.MustCompile("[^a-zA-Z0-9 -]+")
@ -42,13 +43,20 @@ func Render(p *core.Page) string {
func spaceReplace(s string) string {
return whiteSpace.ReplaceAllString(s, "+")
//TODO remove
//return strings.Replace(s, " ", "+", -1)
}
func makeLinkTitle(t string) (newTitle string, title string) {
title = titleRe.ReplaceAllString(t, "")
newTitle = spaceReplace(title)
func Title(title string) string {
return spaceReplace(titleRe.ReplaceAllString(title, ""))
}
func StoreTitle(section, title string) string {
return section + "/" + title
}
func UnstoreTitle(storeTitle string) (section, title string) {
if a := strings.Split(storeTitle, "/"); len(a) == 2 {
return a[0], a[1]
}
return
}
@ -56,10 +64,11 @@ func buildIndex(html string) (string, string) {
var ret string
m := make(map[string]int)
hn := reIndex.FindAllStringSubmatch(html, -1)
html = reHeader.ReplaceAllString(html, `${1} id="${2}">${2}${3}`)
//html = reHeader.ReplaceAllString(html, `${1} id="${2}">${2}${3}`)
html = reHeader.ReplaceAllString(html, `<a id="${2}" class="anchor"></a>${1}${2}${3}`)
html = reLink.ReplaceAllStringFunc(html, spaceReplace)
for k, v := range hn {
link, _ := makeLinkTitle(v[2])
link := Title(v[2])
i := m[link]
m[link] = i + 1
newLink := link + strconv.Itoa(i)
@ -119,11 +128,9 @@ func closeTag(j int) (ret string) {
}
func renderResult(res []core.Result) (html string) {
//TODO fmt.Sprintf ?
for _, r := range res {
html += `<a href="/` + r.StoreTitle + `"><b>` + r.Title + "</b></a>" +
`<pre style="white-space: pre-wrap">` + r.Text + "</pre><br>"
}
return
}