From 9b9d467ce422e96cc828c29c3e50e8bd0ac33ec5 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Fri, 23 Jul 2021 14:00:37 -0500 Subject: [PATCH] Add CLRI/TLRI handling --- public/style.css | 42 +++++--- src/hmnurl/hmnurl_test.go | 4 +- src/hmnurl/urls.go | 6 +- src/parsing/parsing.go | 2 +- src/parsing/parsing_test.go | 14 +-- src/parsing/wasm/parsingmain.go | 2 +- src/rawdata/scss/_core.scss | 15 ++- src/rawdata/scss/_forms.scss | 2 +- src/rawdata/scss/_globals.scss | 9 +- src/templates/src/feed.html | 7 +- src/templates/src/forum_category.html | 8 +- src/templates/src/forum_thread.html | 8 +- src/templates/src/include/pagination.html | 2 +- src/website/feed.go | 2 +- src/website/forums.go | 121 +++++++++++++++++++++- src/website/podcast.go | 2 +- src/website/routes.go | 7 +- 17 files changed, 199 insertions(+), 54 deletions(-) diff --git a/public/style.css b/public/style.css index 176e21ef..9fea678f 100644 --- a/public/style.css +++ b/public/style.css @@ -4690,7 +4690,11 @@ code, .code { padding-top: 0; padding-bottom: 0; } -.pv1, .optionbar .options > * { +.pv1, +.optionbar .options button, +.optionbar .options .button, +.optionbar .options input[type=button], +.optionbar .options input[type=submit] { padding-top: 0.25rem; padding-bottom: 0.25rem; } @@ -4730,7 +4734,11 @@ input[type=submit] { padding-left: 0.25rem; padding-right: 0.25rem; } -.ph2, .optionbar .options > *, .pagination .button { +.ph2, +.optionbar .options button, +.optionbar .options .button, +.optionbar .options input[type=button], +.optionbar .options input[type=submit], .pagination .button { padding-left: 0.5rem; padding-right: 0.5rem; } @@ -5029,7 +5037,11 @@ input[type=submit] { .pv1-ns { padding-top: 0.25rem; padding-bottom: 0.25rem; } - .pv2-ns, .optionbar .options > * { + .pv2-ns, + .optionbar .options button, + .optionbar .options .button, + .optionbar .options input[type=button], + .optionbar .options input[type=submit] { padding-top: 0.5rem; padding-bottom: 0.5rem; } .pv3-ns, header .menu-bar .items a { @@ -7740,14 +7752,17 @@ header { @media screen and (min-width: 30em) { .optionbar .options { flex-direction: row; } } - - .optionbar button, - .optionbar .button, - .optionbar input[type=button], - .optionbar input[type=submit] { - border: none; - background: none; - font-weight: normal; } + + .optionbar .options button, + .optionbar .options .button, + .optionbar .options input[type=button], + .optionbar .options input[type=submit] { + display: inline-flex; + border: none; + background: none; + font-weight: normal; + font-family: inherit; + line-height: inherit; } .optionbar .group { display: inline-block; height: 100%; @@ -8447,9 +8462,12 @@ input[type=submit] { .button.lite, input[type=button].lite, input[type=submit].lite { + display: inline-flex; border: none; background: none; - font-weight: normal; } + font-weight: normal; + font-family: inherit; + line-height: inherit; } button.inline-button, .button.inline-button, diff --git a/src/hmnurl/hmnurl_test.go b/src/hmnurl/hmnurl_test.go index d587caee..d704b673 100644 --- a/src/hmnurl/hmnurl_test.go +++ b/src/hmnurl/hmnurl_test.go @@ -395,8 +395,8 @@ func TestPublic(t *testing.T) { AssertRegexMatch(t, BuildUserFile("mylogo.png"), RegexPublic, nil) } -func TestMarkRead(t *testing.T) { - AssertRegexMatch(t, BuildMarkRead(5), RegexMarkRead, map[string]string{"catid": "5"}) +func TestForumCategoryMarkRead(t *testing.T) { + AssertRegexMatch(t, BuildForumCategoryMarkRead(5), RegexForumCategoryMarkRead, map[string]string{"catid": "5"}) } func AssertSubdomain(t *testing.T, fullUrl string, expectedSubdomain string) { diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 891b3148..74e09394 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -803,17 +803,17 @@ func BuildUserFile(filepath string) string { * Other */ -var RegexMarkRead = regexp.MustCompile(`^/_markread/(?P\d+)$`) +var RegexForumCategoryMarkRead = regexp.MustCompile(`^/markread/(?P\d+)$`) // NOTE(asaf): categoryId == 0 means ALL CATEGORIES -func BuildMarkRead(categoryId int) string { +func BuildForumCategoryMarkRead(categoryId int) string { defer CatchPanic() if categoryId < 0 { panic(oops.New(nil, "Invalid category ID (%d), must be >= 0", categoryId)) } var builder strings.Builder - builder.WriteString("/_markread/") + builder.WriteString("/markread/") builder.WriteString(strconv.Itoa(categoryId)) return Url(builder.String(), nil) diff --git a/src/parsing/parsing.go b/src/parsing/parsing.go index 9e81ded3..fbd70da7 100644 --- a/src/parsing/parsing.go +++ b/src/parsing/parsing.go @@ -25,7 +25,7 @@ var PlaintextMarkdown = goldmark.New( goldmark.WithRenderer(plaintextRenderer{}), ) -func ParsePostInput(source string, md goldmark.Markdown) string { +func ParseMarkdown(source string, md goldmark.Markdown) string { var buf bytes.Buffer if err := md.Convert([]byte(source), &buf); err != nil { panic(err) diff --git a/src/parsing/parsing_test.go b/src/parsing/parsing_test.go index cd2a611c..1e68bdfa 100644 --- a/src/parsing/parsing_test.go +++ b/src/parsing/parsing_test.go @@ -10,14 +10,14 @@ import ( func TestMarkdown(t *testing.T) { t.Run("fenced code blocks", func(t *testing.T) { t.Run("multiple lines", func(t *testing.T) { - html := ParsePostInput("```\nmultiple lines\n\tof code\n```", RealMarkdown) + html := ParseMarkdown("```\nmultiple lines\n\tof code\n```", RealMarkdown) t.Log(html) assert.Equal(t, 1, strings.Count(html, " * { - @extend .ph2; - @extend .pv1; - @extend .pv2-ns; + & { + #{$buttons} { + @include lite-button; + @extend .ph2; + @extend .pv1; + @extend .pv2-ns; + } } } - #{$buttons} { - @include lite-button; - } - .group { display: inline-block; height: 100%; diff --git a/src/rawdata/scss/_forms.scss b/src/rawdata/scss/_forms.scss index 357f1ef9..906725cb 100644 --- a/src/rawdata/scss/_forms.scss +++ b/src/rawdata/scss/_forms.scss @@ -148,7 +148,7 @@ input, select, textarea { } &.lite { - @include lite-button; + @include lite-button; } // UNUSED diff --git a/src/rawdata/scss/_globals.scss b/src/rawdata/scss/_globals.scss index f12c5c4d..75d49233 100644 --- a/src/rawdata/scss/_globals.scss +++ b/src/rawdata/scss/_globals.scss @@ -45,9 +45,12 @@ will throw an error. } @mixin lite-button { - border: none; - background: none; - font-weight: normal; + display: inline-flex; + border: none; + background: none; + font-weight: normal; + font-family: inherit; + line-height: inherit; } $buttons: " diff --git a/src/templates/src/feed.html b/src/templates/src/feed.html index f23eae3e..937b06ce 100644 --- a/src/templates/src/feed.html +++ b/src/templates/src/feed.html @@ -10,9 +10,12 @@
- 4 RSS Feed + 4 RSS Feed {{ if .User }} - Mark all posts on site as read +
+ {{ csrftoken .Session }} + +
{{ end }}
diff --git a/src/templates/src/forum_category.html b/src/templates/src/forum_category.html index da2545f8..e9f6aad9 100644 --- a/src/templates/src/forum_category.html +++ b/src/templates/src/forum_category.html @@ -35,9 +35,11 @@ {{ define "forum_category_options" }}
{{ if .User }} - + New Thread - {{/* TODO(asaf): Mark read should probably be a POST, since it's destructive and we would probably want CSRF for it */}} - Mark threads here as read + + New Thread +
+ {{ csrftoken .Session }} + +
{{ else }} Log in to post a new thread {{ end }} diff --git a/src/templates/src/forum_thread.html b/src/templates/src/forum_thread.html index d270e5ce..df996c22 100644 --- a/src/templates/src/forum_thread.html +++ b/src/templates/src/forum_thread.html @@ -3,8 +3,12 @@ {{ define "content" }}
- ← Back to index - {{ template "pagination.html" .Pagination }} + +
+ {{ template "pagination.html" .Pagination }} +
{{ range .Posts }}
diff --git a/src/templates/src/include/pagination.html b/src/templates/src/include/pagination.html index edcaf0e0..c203fde3 100644 --- a/src/templates/src/include/pagination.html +++ b/src/templates/src/include/pagination.html @@ -1,5 +1,5 @@ {{- /*gotype: git.handmade.network/hmn/hmn/src/templates.Pagination*/ -}} -