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
b541c717
Commit
b541c717
authored
Apr 16, 2016
by
Tobias Weingartner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to markdown a directory with a template.
parent
e652d12c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
3 deletions
+14
-3
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+1
-2
middleware/markdown/metadata/metadata.go
middleware/markdown/metadata/metadata.go
+4
-0
middleware/markdown/process.go
middleware/markdown/process.go
+9
-1
No files found.
middleware/markdown/markdown.go
View file @
b541c717
...
...
@@ -89,7 +89,6 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// Set path to found index file
fpath
=
idx
_
=
dirents
}
// If supported extension, process it
...
...
@@ -117,7 +116,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
Req
:
r
,
URL
:
r
.
URL
,
}
html
,
err
:=
cfg
.
Markdown
(
fpath
,
body
,
ctx
)
html
,
err
:=
cfg
.
Markdown
(
fpath
,
body
,
dirents
,
ctx
)
if
err
!=
nil
{
return
http
.
StatusInternalServerError
,
err
}
...
...
middleware/markdown/metadata/metadata.go
View file @
b541c717
...
...
@@ -3,6 +3,7 @@ package metadata
import
(
"bufio"
"bytes"
"os"
"time"
)
...
...
@@ -30,6 +31,9 @@ type Metadata struct {
// Flags to be used with Template
Flags
map
[
string
]
bool
// Directory entries present, if a directory
Dirents
[]
os
.
FileInfo
}
// NewMetadata() returns a new Metadata struct, loaded with the given map
...
...
middleware/markdown/process.go
View file @
b541c717
package
markdown
import
(
"os"
"path/filepath"
"github.com/mholt/caddy/middleware"
...
...
@@ -10,7 +11,7 @@ import (
// Markdown processes the contents of a page in b. It parses the metadata
// (if any) and uses the template (if found).
func
(
c
*
Config
)
Markdown
(
requestPath
string
,
b
[]
byte
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
func
(
c
*
Config
)
Markdown
(
requestPath
string
,
b
[]
byte
,
dirents
[]
os
.
FileInfo
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
parser
:=
metadata
.
GetParser
(
b
)
markdown
:=
parser
.
Markdown
()
mdata
:=
parser
.
Metadata
()
...
...
@@ -33,5 +34,12 @@ func (c *Config) Markdown(requestPath string, b []byte, ctx middleware.Context)
}
mdata
.
Variables
[
"title"
]
=
title
if
len
(
dirents
)
>
0
{
mdata
.
Flags
[
"dirents"
]
=
true
mdata
.
Dirents
=
dirents
}
else
{
mdata
.
Flags
[
"dirents"
]
=
false
}
return
execTemplate
(
c
,
mdata
,
ctx
)
}
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