Skip to content

Commit

Permalink
Speed up toc and fixed /tags/#ref /categories/#ref links
Browse files Browse the repository at this point in the history
  • Loading branch information
hugozhu committed Mar 11, 2013
1 parent 59d567f commit 4ab86f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func MarkdownToHtml(content string) (str string) {

str = string(Markdown([]byte(content), renderer, extensions))

found := navRegex.FindIndex([]byte(str))
if len(found) > 0 {
toc := str[found[0]:found[1]]
str = str[found[1]:]
str = strings.Replace(str, TOC_MARKUP, toc, -1)
if htmlFlags&HTML_TOC == 1 {
found := navRegex.FindIndex([]byte(str))
if len(found) > 0 {
toc := str[found[0]:found[1]]
str = str[found[1]:]
str = strings.Replace(str, TOC_MARKUP, toc, -1)
}
}
return str
}
8 changes: 4 additions & 4 deletions payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func BuildPlayload(root string) (payload map[string]interface{}, err error) {
for _, _tag := range post.Tags() {
tag := tags[_tag]
if tag == nil {
tag = &Tag{0, _tag, make([]string, 0), "/tags#" + EncodePathInfo(_tag) + "-ref"}
tag = &Tag{0, _tag, make([]string, 0), "/tags/#" + EncodePathInfo(_tag) + "-ref"}
tags[_tag] = tag
}
tag.Count += 1
Expand All @@ -253,7 +253,7 @@ func BuildPlayload(root string) (payload map[string]interface{}, err error) {
for _, _catalog := range post.Categories() {
catalog := catalogs[_catalog]
if catalog == nil {
catalog = &Catalog{0, _catalog, make([]string, 0), "/categories#" + EncodePathInfo(_catalog) + "-ref"}
catalog = &Catalog{0, _catalog, make([]string, 0), "/categories/#" + EncodePathInfo(_catalog) + "-ref"}
catalogs[_catalog] = catalog
}
catalog.Count += 1
Expand Down Expand Up @@ -510,8 +510,8 @@ func AsStrings(v interface{}) (strs []string) {

// 转为URL友好的路径
func EncodePathInfo(pathinfo string) string {
pathinfo = strings.Replace(pathinfo, " ", "_", -1)
pathinfo = strings.Replace(pathinfo, ":", "_", -1)
pathinfo = strings.Replace(pathinfo, " ", "-", -1)
pathinfo = strings.Replace(pathinfo, ":", "-", -1)
return URL.QueryEscape(pathinfo)
}

Expand Down
4 changes: 2 additions & 2 deletions payload_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (webSite *WebSite) LoadPosts() {
for _, _tag := range post.Tags {
tag := tags[_tag]
if tag == nil {
tag = &Tag{0, _tag, make([]string, 0), "/tags#" + EncodePathInfo(_tag) + "-ref"}
tag = &Tag{0, _tag, make([]string, 0), "/tags/#" + EncodePathInfo(_tag) + "-ref"}
tags[_tag] = tag
}
tag.Count += 1
Expand All @@ -244,7 +244,7 @@ func (webSite *WebSite) LoadPosts() {
for _, _catalog := range post.Categories {
catalog := catalogs[_catalog]
if catalog == nil {
catalog = &Catalog{0, _catalog, make([]string, 0), "/categories#" + EncodePathInfo(_catalog) + "-ref"}
catalog = &Catalog{0, _catalog, make([]string, 0), "/categories/#" + EncodePathInfo(_catalog) + "-ref"}
catalogs[_catalog] = catalog
}
catalog.Count += 1
Expand Down

0 comments on commit 4ab86f0

Please sign in to comment.