mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added versioning to view
Former-commit-id: 68a23d84e8fe85c29b6acba7e54fda26b06c81a9 [formerly c437e34b2c74ca9295a1eefdbcd3b2856f9470b6] [formerly 70504642b2871a600d5150081c13b3fc8c14e578 [formerly 2fe84ff14842a8e8670560e7ec0d857a7a18997b [formerlyf6cb433106
]]] Former-commit-id: b23ed0e48e0e8db9786bf91a101cf28c6012fd82 [formerly f34f0ad3994ebe5b00cceb4d2052e4b1c55b7796] Former-commit-id: 2c5902a86996f9287c0890b32945987085428ef7 Former-commit-id:529e6c5918
This commit is contained in:
parent
6b3d8a18c4
commit
9e655c497b
19
routes.go
19
routes.go
@ -65,14 +65,12 @@ func everythingElse(c *gin.Context) {
|
||||
option := c.Param("option")
|
||||
title := c.Param("title")
|
||||
if option == "/view" {
|
||||
var p CowyoData
|
||||
err := p.load(strings.ToLower(title))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
renderMarkdown(c, p.CurrentText, title)
|
||||
version := c.DefaultQuery("version", "-1")
|
||||
versionNum, _ := strconv.Atoi(version)
|
||||
currentText, versions, _ := getCurrentText(title, versionNum)
|
||||
renderMarkdown(c, currentText, title, versions)
|
||||
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
|
||||
renderMarkdown(c, listEverything(), "Everything")
|
||||
renderMarkdown(c, listEverything(), "ls", nil)
|
||||
} else if option == "/list" {
|
||||
renderList(c, title)
|
||||
} 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)
|
||||
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
|
||||
fmt.Println(string(unsafe))
|
||||
@ -113,8 +111,9 @@ func renderMarkdown(c *gin.Context, currentText string, title string) {
|
||||
|
||||
html2 = strings.Replace(html2, "$", "$", -1)
|
||||
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
||||
"Title": title,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"Title": title,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"Versions": versions,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,17 @@
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<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="/about/view">About</a></li>
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user