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