mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Trying to make a /read
This commit is contained in:
parent
0ef75a919c
commit
5ae5c91945
5
Makefile
5
Makefile
@ -9,6 +9,11 @@ build:
|
||||
go-bindata static/... templates/...
|
||||
go build ${LDFLAGS}
|
||||
|
||||
.PHONY: quick
|
||||
quick:
|
||||
go-bindata static/... templates/...
|
||||
go build
|
||||
|
||||
.PHONY: linuxarm
|
||||
linuxarm:
|
||||
env GOOS=linux GOARCH=arm go build ${LDFLAGS} -o dist/cowyo_linux_arm
|
||||
|
18
handlers.go
18
handlers.go
@ -149,6 +149,7 @@ func generateSiteMap() (sitemap string) {
|
||||
sitemap += "</urlset>"
|
||||
return
|
||||
}
|
||||
|
||||
func handlePageRequest(c *gin.Context) {
|
||||
page := c.Param("page")
|
||||
command := c.Param("command")
|
||||
@ -174,13 +175,19 @@ func handlePageRequest(c *gin.Context) {
|
||||
c.Data(http.StatusOK, contentType(filename), data)
|
||||
return
|
||||
}
|
||||
p := Open(page)
|
||||
fmt.Println(command)
|
||||
if len(command) < 2 {
|
||||
c.Redirect(302, "/"+page+"/edit")
|
||||
fmt.Println(p.IsPublished)
|
||||
if p.IsPublished {
|
||||
c.Redirect(302, "/"+page+"/read")
|
||||
} else {
|
||||
c.Redirect(302, "/"+page+"/edit")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
version := c.DefaultQuery("version", "ajksldfjl")
|
||||
p := Open(page)
|
||||
|
||||
// Disallow anything but viewing locked/encrypted pages
|
||||
if (p.IsEncrypted || p.IsLocked) &&
|
||||
@ -232,7 +239,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
versionsChangeSums = reverseSliceInt(versionsChangeSums)
|
||||
}
|
||||
|
||||
if command[0:2] == "/r" {
|
||||
if command[0:3] == "/ra" {
|
||||
c.Writer.Header().Set("Content-Type", contentType(p.Name))
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
||||
@ -246,7 +253,8 @@ func handlePageRequest(c *gin.Context) {
|
||||
log.Debug("%v", command[0:2] != "/e" &&
|
||||
command[0:2] != "/v" &&
|
||||
command[0:2] != "/l" &&
|
||||
command[0:2] != "/h")
|
||||
command[0:2] != "/h" &&
|
||||
command[0:2] != "/r")
|
||||
|
||||
var FileNames, FileLastEdited []string
|
||||
var FileSizes, FileNumChanges []int
|
||||
@ -260,6 +268,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
"ViewPage": command[0:2] == "/v", // /view
|
||||
"ListPage": command[0:2] == "/l", // /list
|
||||
"HistoryPage": command[0:2] == "/h", // /history
|
||||
"ReadPage": command[0:2] == "/r", // /history
|
||||
"DontKnowPage": command[0:2] != "/e" &&
|
||||
command[0:2] != "/v" &&
|
||||
command[0:2] != "/l" &&
|
||||
@ -282,6 +291,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
"HasDotInName": strings.Contains(page, "."),
|
||||
"RecentlyEdited": getRecentlyEdited(page, c),
|
||||
"IsPublished": p.IsPublished,
|
||||
"CustomCSS": "",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -22,15 +22,17 @@
|
||||
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
|
||||
<meta name="theme-color" content="#fff">
|
||||
|
||||
<script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/menus-min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/base-min.css">
|
||||
<link rel="stylesheet" href="/static/css/highlight.css">
|
||||
<script src="/static/js/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="/static/js/highlight.pack.js"></script>
|
||||
{{ if and .CustomCSS .IsPublished }}
|
||||
{{ else }}
|
||||
<script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/menus-min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/base-min.css">
|
||||
<link rel="stylesheet" href="/static/css/highlight.css">
|
||||
<script src="/static/js/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="/static/js/highlight.pack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
<style type="text/css">
|
||||
{{ if .ListPage }}
|
||||
/* Required for lists */
|
||||
span { cursor: pointer; }
|
||||
@ -129,9 +131,8 @@ body#pad textarea {
|
||||
padding-right: 20%;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</style>
|
||||
{{ end }}
|
||||
<title>{{ .Page }}</title>
|
||||
|
||||
|
||||
@ -478,9 +479,18 @@ body#pad textarea {
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body id="pad">
|
||||
<article class="markdown-body">
|
||||
|
||||
{{ if .ReadPage }}
|
||||
<div id="wrap">
|
||||
<div id="rendered">
|
||||
{{ .RenderedPage }}
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
|
||||
|
||||
<div class="pure-menu pure-menu-horizontal" id="menu">
|
||||
<ul class="pure-menu-list">
|
||||
<li></li>
|
||||
@ -594,8 +604,9 @@ body#pad textarea {
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{{ end }}
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user