1
0
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:
Zack Scholl 2017-11-02 06:27:39 -06:00
parent 0ef75a919c
commit 5ae5c91945
3 changed files with 43 additions and 17 deletions

View File

@ -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

View File

@ -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": "",
}) })
} }

View File

@ -22,15 +22,17 @@
<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">
<script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script> {{ if and .CustomCSS .IsPublished }}
<link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css"> {{ else }}
<link rel="stylesheet" type="text/css" href="/static/css/menus-min.css"> <script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/base-min.css"> <link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css">
<link rel="stylesheet" href="/static/css/highlight.css"> <link rel="stylesheet" type="text/css" href="/static/css/menus-min.css">
<script src="/static/js/highlight.min.js"></script> <link rel="stylesheet" type="text/css" href="/static/css/base-min.css">
<script type="text/javascript" src="/static/js/highlight.pack.js"></script> <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 }} {{ if .ListPage }}
/* Required for lists */ /* Required for lists */
span { cursor: pointer; } span { cursor: pointer; }
@ -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>