mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added versioning to view
This commit is contained in:
parent
c15ac624b8
commit
f6cb433106
15
routes.go
15
routes.go
@ -65,14 +65,12 @@ func everythingElse(c *gin.Context) {
|
|||||||
option := c.Param("option")
|
option := c.Param("option")
|
||||||
title := c.Param("title")
|
title := c.Param("title")
|
||||||
if option == "/view" {
|
if option == "/view" {
|
||||||
var p CowyoData
|
version := c.DefaultQuery("version", "-1")
|
||||||
err := p.load(strings.ToLower(title))
|
versionNum, _ := strconv.Atoi(version)
|
||||||
if err != nil {
|
currentText, versions, _ := getCurrentText(title, versionNum)
|
||||||
panic(err)
|
renderMarkdown(c, currentText, title, versions)
|
||||||
}
|
|
||||||
renderMarkdown(c, p.CurrentText, title)
|
|
||||||
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
|
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
|
||||||
renderMarkdown(c, listEverything(), "Everything")
|
renderMarkdown(c, listEverything(), "ls", nil)
|
||||||
} else if option == "/list" {
|
} else if option == "/list" {
|
||||||
renderList(c, title)
|
renderList(c, title)
|
||||||
} else if title == "static" {
|
} else if title == "static" {
|
||||||
@ -91,7 +89,7 @@ func serveStaticFile(c *gin.Context, option string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderMarkdown(c *gin.Context, currentText string, title string) {
|
func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo) {
|
||||||
fmt.Println(currentText)
|
fmt.Println(currentText)
|
||||||
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
|
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
|
||||||
fmt.Println(string(unsafe))
|
fmt.Println(string(unsafe))
|
||||||
@ -115,6 +113,7 @@ func renderMarkdown(c *gin.Context, currentText string, title string) {
|
|||||||
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
||||||
"Title": title,
|
"Title": title,
|
||||||
"Body": template.HTML([]byte(html2)),
|
"Body": template.HTML([]byte(html2)),
|
||||||
|
"Versions": versions,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,17 @@
|
|||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li><a href="/{{ .Title }}">Edit</a></li>
|
<li><a href="/{{ .Title }}">Edit</a></li>
|
||||||
<li class="active"><a href="/{{ .Title }}/view">View</a></li>
|
<li class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active">View <span class="caret"></span></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li class="dropdown-header">Previous versions</li>
|
||||||
|
<li><a href="/{{ .Title }}/view?version=0">First</a></li>
|
||||||
|
{{ range .Versions }}
|
||||||
|
<li><a href="/{{ $.Title }}/view?version={{ .VersionNum }}">{{ .VersionDate }}</a></li>
|
||||||
|
{{ end }}
|
||||||
|
<li><a href="/{{ .Title }}/view">Current</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<li><a href="/{{ .Title }}/list">List</a></li>
|
<li><a href="/{{ .Title }}/list">List</a></li>
|
||||||
<li><a href="/about/view">About</a></li>
|
<li><a href="/about/view">About</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user