Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
dc4a5ae1
Commit
dc4a5ae1
authored
Sep 10, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #237 from LK4D4/fix_lock
markdown: Use markdown.Config as pointer everywhere
parents
55de0370
da7b9a6b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
20 deletions
+20
-20
config/setup/markdown.go
config/setup/markdown.go
+4
-4
middleware/markdown/generator.go
middleware/markdown/generator.go
+2
-2
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+3
-3
middleware/markdown/markdown_test.go
middleware/markdown/markdown_test.go
+6
-6
middleware/markdown/page.go
middleware/markdown/page.go
+1
-1
middleware/markdown/process.go
middleware/markdown/process.go
+4
-4
No files found.
config/setup/markdown.go
View file @
dc4a5ae1
...
...
@@ -28,7 +28,7 @@ func Markdown(c *Controller) (middleware.Middleware, error) {
// Sweep the whole path at startup to at least generate link index, maybe generate static site
c
.
Startup
=
append
(
c
.
Startup
,
func
()
error
{
for
i
:=
range
mdconfigs
{
cfg
:=
&
mdconfigs
[
i
]
cfg
:=
mdconfigs
[
i
]
// Generate link index and static files (if enabled)
if
err
:=
markdown
.
GenerateStatic
(
md
,
cfg
);
err
!=
nil
{
...
...
@@ -50,11 +50,11 @@ func Markdown(c *Controller) (middleware.Middleware, error) {
},
nil
}
func
markdownParse
(
c
*
Controller
)
([]
markdown
.
Config
,
error
)
{
var
mdconfigs
[]
markdown
.
Config
func
markdownParse
(
c
*
Controller
)
([]
*
markdown
.
Config
,
error
)
{
var
mdconfigs
[]
*
markdown
.
Config
for
c
.
Next
()
{
md
:=
markdown
.
Config
{
md
:=
&
markdown
.
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
Templates
:
make
(
map
[
string
]
string
),
StaticFiles
:
make
(
map
[
string
]
string
),
...
...
middleware/markdown/generator.go
View file @
dc4a5ae1
...
...
@@ -102,7 +102,7 @@ func generateStaticHTML(md Markdown, cfg *Config) error {
// Generate the static file
ctx
:=
middleware
.
Context
{
Root
:
md
.
FileSys
}
_
,
err
=
md
.
Process
(
*
cfg
,
reqPath
,
body
,
ctx
)
_
,
err
=
md
.
Process
(
cfg
,
reqPath
,
body
,
ctx
)
if
err
!=
nil
{
return
err
}
...
...
@@ -115,7 +115,7 @@ func generateStaticHTML(md Markdown, cfg *Config) error {
}
// computeDirHash computes an hash on static directory of c.
func
computeDirHash
(
md
Markdown
,
c
Config
)
(
string
,
error
)
{
func
computeDirHash
(
md
Markdown
,
c
*
Config
)
(
string
,
error
)
{
dir
:=
filepath
.
Join
(
md
.
Root
,
c
.
PathScope
)
if
_
,
err
:=
os
.
Stat
(
dir
);
err
!=
nil
{
return
""
,
err
...
...
middleware/markdown/markdown.go
View file @
dc4a5ae1
...
...
@@ -27,7 +27,7 @@ type Markdown struct {
Next
middleware
.
Handler
// The list of markdown configurations
Configs
[]
Config
Configs
[]
*
Config
// The list of index files to try
IndexFiles
[]
string
...
...
@@ -83,7 +83,7 @@ type Config struct {
// IsValidExt checks to see if an extension is a valid markdown extension
// for config.
func
(
c
Config
)
IsValidExt
(
ext
string
)
bool
{
func
(
c
*
Config
)
IsValidExt
(
ext
string
)
bool
{
for
_
,
e
:=
range
c
.
Extensions
{
if
e
==
ext
{
return
true
...
...
@@ -121,7 +121,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// if development is set, scan directory for file changes for links.
if
cfg
.
Development
{
if
err
:=
GenerateStatic
(
md
,
&
cfg
);
err
!=
nil
{
if
err
:=
GenerateStatic
(
md
,
cfg
);
err
!=
nil
{
log
.
Println
(
"On-demand generation error (markdown):"
,
err
)
}
}
...
...
middleware/markdown/markdown_test.go
View file @
dc4a5ae1
...
...
@@ -21,8 +21,8 @@ func TestMarkdown(t *testing.T) {
md
:=
Markdown
{
Root
:
"./testdata"
,
FileSys
:
http
.
Dir
(
"./testdata"
),
Configs
:
[]
Config
{
Config
{
Configs
:
[]
*
Config
{
&
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
PathScope
:
"/blog"
,
Extensions
:
[]
string
{
".md"
},
...
...
@@ -32,7 +32,7 @@ func TestMarkdown(t *testing.T) {
StaticDir
:
DefaultStaticDir
,
StaticFiles
:
make
(
map
[
string
]
string
),
},
Config
{
&
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
PathScope
:
"/log"
,
Extensions
:
[]
string
{
".md"
},
...
...
@@ -42,7 +42,7 @@ func TestMarkdown(t *testing.T) {
StaticDir
:
DefaultStaticDir
,
StaticFiles
:
make
(
map
[
string
]
string
),
},
Config
{
&
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
PathScope
:
"/og"
,
Extensions
:
[]
string
{
".md"
},
...
...
@@ -69,7 +69,7 @@ func TestMarkdown(t *testing.T) {
}
for
i
:=
range
md
.
Configs
{
c
:=
&
md
.
Configs
[
i
]
c
:=
md
.
Configs
[
i
]
if
err
:=
GenerateStatic
(
md
,
c
);
err
!=
nil
{
t
.
Fatalf
(
"Error: %v"
,
err
)
}
...
...
@@ -221,7 +221,7 @@ Welcome to title!
w
.
Wait
()
f
=
func
()
{
GenerateStatic
(
md
,
&
md
.
Configs
[
0
])
GenerateStatic
(
md
,
md
.
Configs
[
0
])
w
.
Done
()
}
for
i
:=
0
;
i
<
5
;
i
++
{
...
...
middleware/markdown/page.go
View file @
dc4a5ae1
...
...
@@ -83,7 +83,7 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) bool {
return
false
}
hash
,
err
:=
computeDirHash
(
md
,
*
cfg
)
hash
,
err
:=
computeDirHash
(
md
,
cfg
)
// same hash, return.
if
err
==
nil
&&
hash
==
cfg
.
linksHash
{
...
...
middleware/markdown/process.go
View file @
dc4a5ae1
...
...
@@ -26,7 +26,7 @@ type MarkdownData struct {
// Process processes the contents of a page in b. It parses the metadata
// (if any) and uses the template (if found).
func
(
md
Markdown
)
Process
(
c
Config
,
requestPath
string
,
b
[]
byte
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
func
(
md
Markdown
)
Process
(
c
*
Config
,
requestPath
string
,
b
[]
byte
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
var
metadata
=
Metadata
{
Variables
:
make
(
map
[
string
]
string
)}
var
markdown
[]
byte
var
err
error
...
...
@@ -82,7 +82,7 @@ func (md Markdown) Process(c Config, requestPath string, b []byte, ctx middlewar
// processTemplate processes a template given a requestPath,
// template (tmpl) and metadata
func
(
md
Markdown
)
processTemplate
(
c
Config
,
requestPath
string
,
tmpl
[]
byte
,
metadata
Metadata
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
func
(
md
Markdown
)
processTemplate
(
c
*
Config
,
requestPath
string
,
tmpl
[]
byte
,
metadata
Metadata
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
// if template is not specified,
// use the default template
if
tmpl
==
nil
{
...
...
@@ -123,7 +123,7 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me
// generatePage generates a static html page from the markdown in content if c.StaticDir
// is a non-empty value, meaning that the user enabled static site generation.
func
(
md
Markdown
)
generatePage
(
c
Config
,
requestPath
string
,
content
[]
byte
)
error
{
func
(
md
Markdown
)
generatePage
(
c
*
Config
,
requestPath
string
,
content
[]
byte
)
error
{
// Only generate the page if static site generation is enabled
if
c
.
StaticDir
!=
""
{
// if static directory is not existing, create it
...
...
@@ -160,7 +160,7 @@ func (md Markdown) generatePage(c Config, requestPath string, content []byte) er
}
// defaultTemplate constructs a default template.
func
defaultTemplate
(
c
Config
,
metadata
Metadata
,
requestPath
string
)
[]
byte
{
func
defaultTemplate
(
c
*
Config
,
metadata
Metadata
,
requestPath
string
)
[]
byte
{
var
scripts
,
styles
bytes
.
Buffer
for
_
,
style
:=
range
c
.
Styles
{
styles
.
WriteString
(
strings
.
Replace
(
cssTemplate
,
"{{url}}"
,
style
,
1
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment