mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-01 00:23:48 +03:00
Merge branch 'master' of https://github.com/mholt/caddy
This commit is contained in:
commit
60690c78ae
8 changed files with 54 additions and 20 deletions
|
@ -20,7 +20,7 @@ const (
|
|||
Name = "Caddy"
|
||||
|
||||
// Version is the program version
|
||||
Version = "0.7.3"
|
||||
Version = "0.7.4"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
16
dist/CHANGES.txt
vendored
16
dist/CHANGES.txt
vendored
|
@ -1,12 +1,18 @@
|
|||
CHANGES
|
||||
|
||||
<master>
|
||||
- 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)
|
||||
|
|
2
dist/README.txt
vendored
2
dist/README.txt
vendored
|
@ -1,4 +1,4 @@
|
|||
CADDY 0.7.3
|
||||
CADDY 0.7.4
|
||||
|
||||
Website
|
||||
https://caddyserver.com
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)),
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue