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
Łukasz Nowak
caddy
Commits
2ab46659
Commit
2ab46659
authored
Aug 05, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markdown: Modify development mode to generate links on page requests.
parent
851026d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
37 deletions
+37
-37
config/setup/markdown.go
config/setup/markdown.go
+2
-4
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+8
-0
middleware/markdown/markdown_test.go
middleware/markdown/markdown_test.go
+11
-1
middleware/markdown/page.go
middleware/markdown/page.go
+4
-0
middleware/markdown/watcher.go
middleware/markdown/watcher.go
+12
-32
No files found.
config/setup/markdown.go
View file @
2ab46659
...
...
@@ -36,10 +36,8 @@ func Markdown(c *Controller) (middleware.Middleware, error) {
if
err
:=
markdown
.
GenerateLinks
(
md
,
cfg
);
err
!=
nil
{
return
err
}
// Watch file changes for links generation.
if
cfg
.
Development
{
markdown
.
Watch
(
md
,
cfg
,
0
)
}
else
{
// Watch file changes for links generation if not in development mode.
if
!
cfg
.
Development
{
markdown
.
Watch
(
md
,
cfg
,
markdown
.
DefaultInterval
)
}
...
...
middleware/markdown/markdown.go
View file @
2ab46659
...
...
@@ -4,6 +4,7 @@ package markdown
import
(
"io/ioutil"
"log"
"net/http"
"os"
"strings"
...
...
@@ -119,6 +120,13 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
return
http
.
StatusNotFound
,
nil
}
// if development is set, scan directory for file changes for links.
if
m
.
Development
{
if
err
:=
GenerateLinks
(
md
,
m
);
err
!=
nil
{
log
.
Println
(
err
)
}
}
// if static site is generated, attempt to use it
if
filepath
,
ok
:=
m
.
StaticFiles
[
fpath
];
ok
{
if
fs1
,
err
:=
os
.
Stat
(
filepath
);
err
==
nil
{
...
...
middleware/markdown/markdown_test.go
View file @
2ab46659
...
...
@@ -199,7 +199,7 @@ func getTrue() bool {
}
}
// attempt to trigger race condition
// attempt to trigger race condition
s
var
w
sync
.
WaitGroup
f
:=
func
()
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/log/test.md"
,
nil
)
...
...
@@ -217,6 +217,16 @@ func getTrue() bool {
}
w
.
Wait
()
f
=
func
()
{
GenerateLinks
(
md
,
&
md
.
Configs
[
0
])
w
.
Done
()
}
for
i
:=
0
;
i
<
5
;
i
++
{
w
.
Add
(
1
)
go
f
()
}
w
.
Wait
()
if
err
=
os
.
RemoveAll
(
DefaultStaticDir
);
err
!=
nil
{
t
.
Errorf
(
"Error while removing the generated static files: %v"
,
err
)
}
...
...
middleware/markdown/page.go
View file @
2ab46659
...
...
@@ -79,6 +79,7 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) {
if
_
,
err
:=
os
.
Stat
(
fp
);
os
.
IsNotExist
(
err
)
{
l
.
Lock
()
l
.
lastErr
=
err
l
.
generating
=
false
l
.
Unlock
()
return
}
...
...
@@ -87,6 +88,9 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) {
// same hash, return.
if
err
==
nil
&&
hash
==
cfg
.
linksHash
{
l
.
Lock
()
l
.
generating
=
false
l
.
Unlock
()
return
}
else
if
err
!=
nil
{
log
.
Println
(
"Error:"
,
err
)
...
...
middleware/markdown/watcher.go
View file @
2ab46659
...
...
@@ -20,39 +20,19 @@ func Watch(md Markdown, c *Config, interval time.Duration) (stopChan chan struct
func
TickerFunc
(
interval
time
.
Duration
,
f
func
())
chan
struct
{}
{
stopChan
:=
make
(
chan
struct
{})
if
interval
>
0
{
ticker
:=
time
.
NewTicker
(
interval
)
go
func
()
{
loop
:
for
{
select
{
case
<-
ticker
.
C
:
f
()
case
<-
stopChan
:
ticker
.
Stop
()
break
loop
}
ticker
:=
time
.
NewTicker
(
interval
)
go
func
()
{
loop
:
for
{
select
{
case
<-
ticker
.
C
:
f
()
case
<-
stopChan
:
ticker
.
Stop
()
break
loop
}
}()
}
else
{
go
func
()
{
loop
:
for
{
m
:=
make
(
chan
struct
{})
go
func
()
{
f
()
m
<-
struct
{}{}
}()
select
{
case
<-
m
:
continue
loop
case
<-
stopChan
:
break
loop
}
time
.
Sleep
(
DevInterval
)
}
}()
}
}()
}
return
stopChan
}
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