diff --git a/app/app.go b/app/app.go index babe4930..e73f95b4 100644 --- a/app/app.go +++ b/app/app.go @@ -20,7 +20,7 @@ const ( Name = "Caddy" // Version is the program version - Version = "0.7.3" + Version = "0.7.4" ) var ( diff --git a/dist/CHANGES.txt b/dist/CHANGES.txt index 87ce6eb5..517421ac 100644 --- a/dist/CHANGES.txt +++ b/dist/CHANGES.txt @@ -1,12 +1,18 @@ CHANGES - -- browse: Sort preference persisted in cookie +0.7.4 (July 30, 2015) +- browse: Sorting preference persisted in cookie - browse: Added index.txt and default.txt to list of default files -- markdown: Fix for large markdown files -- redir: Can use variables like log formats can +- browse: Template files may now use Caddy template actions +- markdown: Template files may now use Caddy template actions +- markdown: Several bug fixes, especially for large and empty Markdown files +- markdown: Generate index pages to link to markdown pages (sitegen only) +- markdown: Flatten structure of front matter, changed template variables +- redir: Can use variables (placeholders) like log formats can - redir: Catch-all redirects no longer preserve path; use {uri} instead -- redir: Create redirect tables by opening a redir block +- redir: Syntax supports redirect tables by opening a block +- templates: Renamed .Date to .Now and added .Truncate, .Replace actions +- Other minor internal improvements and more tests 0.7.3 (July 15, 2015) diff --git a/dist/README.txt b/dist/README.txt index 50793686..4a0713b8 100644 --- a/dist/README.txt +++ b/dist/README.txt @@ -1,4 +1,4 @@ -CADDY 0.7.3 +CADDY 0.7.4 Website https://caddyserver.com diff --git a/middleware/browse/browse.go b/middleware/browse/browse.go index 756ca8c8..6868be88 100644 --- a/middleware/browse/browse.go +++ b/middleware/browse/browse.go @@ -120,9 +120,10 @@ func (l Listing) applySort() { } } -// HumanSize returns the size of the file as a human-readable string. +// HumanSize returns the size of the file as a human-readable string +// in IEC format (i.e. power of 2 or base 1024). func (fi FileInfo) HumanSize() string { - return humanize.Bytes(uint64(fi.Size)) + return humanize.IBytes(uint64(fi.Size)) } // HumanModTime returns the modified time of the file as a human-readable string. diff --git a/middleware/context.go b/middleware/context.go index 508ec604..0cd7696c 100644 --- a/middleware/context.go +++ b/middleware/context.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "net/url" + "strings" "text/template" "time" ) @@ -13,7 +14,7 @@ import ( // This file contains the context and functions available for // use in the templates. -// context is the context with which templates are executed. +// Context is the context with which Caddy templates are executed. type Context struct { Root http.FileSystem Req *http.Request @@ -48,8 +49,8 @@ func (c Context) Include(filename string) (string, error) { return buf.String(), nil } -// Date returns the current timestamp in the specified format -func (c Context) Date(format string) string { +// Now returns the current timestamp in the specified format. +func (c Context) Now(format string) string { return time.Now().Format(format) } @@ -114,3 +115,17 @@ func (c Context) Method() string { func (c Context) PathMatches(pattern string) bool { return Path(c.Req.URL.Path).Matches(pattern) } + +// Truncate truncates the input string to the given length. If +// input is shorter than length, the entire string is returned. +func (c Context) Truncate(input string, length int) string { + if len(input) > length { + return input[:length] + } + return input +} + +// Replace replaces instances of find in input with replacement. +func (c Context) Replace(input, find, replacement string) string { + return strings.Replace(input, find, replacement, -1) +} diff --git a/middleware/markdown/markdown_test.go b/middleware/markdown/markdown_test.go index 917cff9b..bb906972 100644 --- a/middleware/markdown/markdown_test.go +++ b/middleware/markdown/markdown_test.go @@ -55,7 +55,7 @@ func TestMarkdown(t *testing.T) { Title: "first", Summary: "", Date: time.Now(), - Url: "/og/first.md", + URL: "/og/first.md", }, }, }, @@ -191,8 +191,8 @@ func getTrue() bool { for i, c := range md.Configs { log.Printf("Test number: %d, configuration links: %v, config: %v", i, c.Links, c) - if c.Links[0].Url != expectedLinks[i] { - t.Fatalf("Expected %v got %v", expectedLinks[i], c.Links[0].Url) + if c.Links[0].URL != expectedLinks[i] { + t.Fatalf("Expected %v got %v", expectedLinks[i], c.Links[0].URL) } } diff --git a/middleware/markdown/page.go b/middleware/markdown/page.go index 91dfb37b..79810075 100644 --- a/middleware/markdown/page.go +++ b/middleware/markdown/page.go @@ -1,6 +1,7 @@ package markdown import ( + "bytes" "io/ioutil" "os" "path/filepath" @@ -16,8 +17,8 @@ const ( // Date format YYYY-MM-DD HH:MM:SS timeLayout = `2006-01-02 15:04:05` - // Length of page summary. - summaryLen = 150 + // Maximum length of page summary. + summaryLen = 500 ) // PageLink represents a statically generated markdown page. @@ -25,7 +26,7 @@ type PageLink struct { Title string Summary string Date time.Time - Url string + URL string } // byDate sorts PageLink by newest date to oldest. @@ -99,15 +100,22 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) { return err } + // truncate summary to maximum length if len(summary) > summaryLen { summary = summary[:summaryLen] + + // trim to nearest word + lastSpace := bytes.LastIndex(summary, []byte(" ")) + if lastSpace != -1 { + summary = summary[:lastSpace] + } } metadata := parser.Metadata() cfg.Links = append(cfg.Links, PageLink{ Title: metadata.Title, - Url: reqPath, + URL: reqPath, Date: metadata.Date, Summary: string(blackfriday.Markdown(summary, PlaintextRenderer{}, 0)), }) diff --git a/middleware/markdown/renderer.go b/middleware/markdown/renderer.go index 8fab8d2a..fb599984 100644 --- a/middleware/markdown/renderer.go +++ b/middleware/markdown/renderer.go @@ -48,7 +48,11 @@ func (r PlaintextRenderer) TitleBlock(out *bytes.Buffer, text []byte) {} func (r PlaintextRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {} -func (r PlaintextRenderer) CodeSpan(out *bytes.Buffer, text []byte) {} +func (r PlaintextRenderer) CodeSpan(out *bytes.Buffer, text []byte) { + out.Write([]byte("`")) + out.Write(text) + out.Write([]byte("`")) +} func (r PlaintextRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { out.Write(text)