Skip to content

Commit

Permalink
reformat lists, allow raw
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Feb 23, 2019
1 parent c2f9619 commit b7159f2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type File struct {
func formattedDate(t time.Time, utcOffset int) string {
loc, err := time.LoadLocation(fmt.Sprintf("Etc/GMT%+d", utcOffset))
if err != nil {
return t.Format("Jan 2 3:04pm 2006")
return t.Format("3:04pm Jan 2 2006")
}
return t.In(loc).Format("Jan 2 3:04pm 2006")
return t.In(loc).Format("3:04pm Jan 2 2006")
}

func (f File) CreatedDate(utcOffset int) string {
Expand Down
21 changes: 21 additions & 0 deletions template_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,25 @@ func (tr *TemplateRender) handleViewEdit(w http.ResponseWriter, r *http.Request)
}
log.Debugf("checked domain %s", time.Since(timerStart))

// check whether want to serve raw
showRaw := r.URL.Query().Get("raw") != ""
log.Debugf("raw page: '%v'", showRaw)

trBytes, err := tr.rwt.fs.GetCacheHTML(pageID)
if err == nil {
err = json.Unmarshal(trBytes, &tr)
if err != nil {
log.Error(err)
} else {
log.Debug("using cache")
if showRaw {
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Type", "text/plain")
gz := gzip.NewWriter(w)
defer gz.Close()
_, err = gz.Write([]byte(tr.File.Data))
return
}
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Type", "text/html")
gz := gzip.NewWriter(w)
Expand Down Expand Up @@ -550,6 +562,15 @@ func (tr *TemplateRender) handleViewEdit(w http.ResponseWriter, r *http.Request)
}
tr.File = f

if showRaw {
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Type", "text/plain")
gz := gzip.NewWriter(w)
defer gz.Close()
_, err = gz.Write([]byte(tr.File.Data))
return
}

// get a specific version
version := r.URL.Query().Get("version")
if version != "" {
Expand Down
6 changes: 4 additions & 2 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
cursor: pointer;
}
.smaller {
font-size: 70%;
font-size: 85%;
}

.grayed {
Expand All @@ -223,7 +223,9 @@

/* rwtxt specific */


summary {
margin-bottom: 0.5em;
}
textarea {
background: rgb(253, 253, 253);
width: 100%;
Expand Down
22 changes: 14 additions & 8 deletions templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
<a href='/{{.Domain}}/{{.RandomUUID}}?edit=1' class='fr'>New page</a>{{end}}</span>
<h1>{{.NumResults}} results for '{{.Search}}'</h1>
<p>Currently in the <strong>{{.Domain}}</strong> domain.</p>
{{range .Files}}
<p>
<a href="/{{$.Domain}}/{{.ID}}">{{.Slug}}</a>
<small class="grey">{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset}}{{else}}{{.ModifiedDate $.UTCOffset}}{{end}}</small>

<blockquote><em>{{.DataHTML}}</em></blockquote>
</p>
{{end}}

<div class="list">
{{range .Files}}
<div>
<div>
<a href="/{{$.Domain}}/{{.ID}}">{{.Slug}}</a>
</div>
<div>
{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset}}{{else}}{{.ModifiedDate $.UTCOffset}}{{end}}
</div>
{{with .DataHTML}}<blockquote><em>{{.}}</em></blockquote>{{end}}
</div>
{{end}}
</div>
</main>
{{template "footer" .}}
37 changes: 22 additions & 15 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,39 @@ <h1>{{if eq .Domain "public"}}Welcome{{else}}{{.Domain}}{{end}}</h1>
</p>
{{ if .Files }}
<h2>Most recent <small>(<a href="/{{.Domain}}/list">all posts</a>)</small></h2>
<ul>
<div class="list">
{{range .Files}}

<li>

<a href="/{{$.Domain}}/{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{.Slug}}{{end}}">{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{replace .Slug "-" " "}}{{end}}</a>
&nbsp;<small class="grey">{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset }}{{else}}{{.ModifiedDate $.UTCOffset }}{{end}}</small>
</li>
<div>
<div>
<a href="/{{$.Domain}}/{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{.Slug}}{{end}}">{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{replace .Slug "-" " "}}{{end}}</a>
</div>
<div>
{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset }}{{else}}{{.ModifiedDate $.UTCOffset }}{{end}}
</div>
</div>
{{end}}
</ul>
</div>
{{end}}

{{ $length := len .MostActiveList }}{{ if ge $length 8 }}
<h2>Most edited</h2>
<ul>
<h2>Most edited</h2>
<div class="list">
{{range .MostActiveList}}
<li>
<a href="/{{$.Domain}}/{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{.Slug}}{{end}}">{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{replace .Slug "-" " "}}{{end}}</a>
&nbsp;<small class="grey">{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset }}{{else}}{{.ModifiedDate $.UTCOffset }}{{end}}</small>
</li>
<div>
<div>
<a href="/{{$.Domain}}/{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{.Slug}}{{end}}">{{if eq (len .Slug) 0}}{{.ID}}{{else}}{{replace .Slug "-" " "}}{{end}}</a>
</div>
<div>
{{ if $.RWTxtConfig.OrderByCreated}}{{.CreatedDate $.UTCOffset }}{{else}}{{.ModifiedDate $.UTCOffset }}{{end}}
</div>
</div>
{{end}}
</ul>
</div>
{{end}}

{{end}}
{{ if and (.SignedIn) (ne .Domain "public")}}
<br>
<details>
<summary>Options</summary>
<form action="/update" method="post">
Expand Down
14 changes: 9 additions & 5 deletions templates/viewedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

<div class="grayed smaller">
<br><br><br>
<a href="/{{.Domain}}/{{.File.ID}}" class="grayed">/{{.Domain}}/{{.File.ID}}</a><br>
{{.File.ModifiedDate .UTCOffset }}<br>
{{.File.Views}} views<br>{{ if (eq .Domain "public") }}{{else}}{{ if .SimilarFiles}}
Related: {{ range .SimilarFiles }}<a href="/{{$.Domain}}/{{.ID}}" class="grayed">{{.Slug}}</a> {{end}}
{{end}}{{end}}
<details>
<summary>{{.File.ModifiedDate .UTCOffset }}</summary>
<a href="/{{.Domain}}/{{.File.ID}}?raw=1" class="grayed">/{{.Domain}}/{{.File.ID}}</a><br>
{{.File.Views}} views<br>
<!-- {{ if (eq .Domain "public") }}{{else}}{{ if .SimilarFiles}}
{{ range .SimilarFiles }}<a href="/{{$.Domain}}/{{.ID}}" class="grayed">{{.Slug}}</a><br> {{end}}
{{end}}{{end}} -->
</details>

</div>
</div>
{{ end }}
Expand Down

0 comments on commit b7159f2

Please sign in to comment.