From 9945ab061dc4faa0858655ffce099f828de9431c Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Fri, 30 Jul 2021 17:32:19 -0500 Subject: [PATCH] Add blog post editing --- src/hmnurl/urls.go | 36 +- src/rawdata/scss/_content.scss | 4 +- src/rawdata/scss/_core.scss | 12 +- src/rawdata/scss/_editor.scss | 43 +-- src/rawdata/scss/_forum.scss | 4 +- .../scss/tachyons/scss/_variables.scss | 1 + src/templates/src/editor.html | 13 +- src/templates/src/editorpreviews.js | 33 ++ src/templates/templates.go | 23 +- src/website/blogs.go | 92 ++++- src/website/forums.go | 317 ++++-------------- src/website/landing.go | 6 +- src/website/post_helper.go | 2 +- src/website/routes.go | 8 + src/website/threads_and_posts_helper.go | 221 +++++++++++- 15 files changed, 465 insertions(+), 350 deletions(-) create mode 100644 src/templates/src/editorpreviews.js diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 3876cd48..1e223eb3 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -414,17 +414,17 @@ func BuildBlog(projectSlug string, page int) string { return ProjectUrl(path, nil, projectSlug) } -var RegexBlogThread = regexp.MustCompile(`^/blog/p/(?P\d+)(-([^/]+))?(/(?P\d+))?$`) +var RegexBlogThread = regexp.MustCompile(`^/blog/p/(?P\d+)(-([^/]+))?$`) -func BuildBlogThread(projectSlug string, threadId int, title string, page int) string { +func BuildBlogThread(projectSlug string, threadId int, title string) string { defer CatchPanic() - builder := buildBlogThreadPath(threadId, title, page) + builder := buildBlogThreadPath(threadId, title) return ProjectUrl(builder.String(), nil, projectSlug) } -func BuildBlogThreadWithPostHash(projectSlug string, threadId int, title string, page int, postId int) string { +func BuildBlogThreadWithPostHash(projectSlug string, threadId int, title string, postId int) string { defer CatchPanic() - builder := buildBlogThreadPath(threadId, title, page) + builder := buildBlogThreadPath(threadId, title) return ProjectUrlWithFragment(builder.String(), nil, projectSlug, strconv.Itoa(postId)) } @@ -463,15 +463,6 @@ func BuildBlogPostReply(projectSlug string, threadId int, postId int) string { return ProjectUrl(builder.String(), nil, projectSlug) } -var RegexBlogPostQuote = regexp.MustCompile(`^/blog/p/(?P\d+)/e/(?P\d+)/quote$`) - -func BuildBlogPostQuote(projectSlug string, threadId int, postId int) string { - defer CatchPanic() - builder := buildBlogPostPath(threadId, postId) - builder.WriteString("/quote") - return ProjectUrl(builder.String(), nil, projectSlug) -} - /* * Library */ @@ -525,6 +516,13 @@ func BuildProjectCSS(color string) string { return Url("/assets/project.css", []Q{{"color", color}}) } +var RegexEditorPreviewsJS = regexp.MustCompile("^/assets/editorpreviews.js$") + +func BuildEditorPreviewsJS() string { + defer CatchPanic() + return Url("/assets/editorpreviews.js", nil) +} + // NOTE(asaf): No Regex or tests for remote assets, since we don't parse it ourselves func BuildS3Asset(s3key string) string { defer CatchPanic() @@ -665,11 +663,7 @@ func buildForumPostPath(subforums []string, threadId int, postId int) *strings.B return builder } -func buildBlogThreadPath(threadId int, title string, page int) *strings.Builder { - if page < 1 { - panic(oops.New(nil, "Invalid blog thread page (%d), must be >= 1", page)) - } - +func buildBlogThreadPath(threadId int, title string) *strings.Builder { if threadId < 1 { panic(oops.New(nil, "Invalid blog thread ID (%d), must be >= 1", threadId)) } @@ -682,10 +676,6 @@ func buildBlogThreadPath(threadId int, title string, page int) *strings.Builder builder.WriteRune('-') builder.WriteString(PathSafeTitle(title)) } - if page > 1 { - builder.WriteRune('/') - builder.WriteString(strconv.Itoa(page)) - } return &builder } diff --git a/src/rawdata/scss/_content.scss b/src/rawdata/scss/_content.scss index 175555c3..b23eb050 100644 --- a/src/rawdata/scss/_content.scss +++ b/src/rawdata/scss/_content.scss @@ -7,7 +7,7 @@ } .monospace { - font-family: "Fira Mono", monospace; + font-family: $monospace-fonts; background-color: rgba(0, 0, 0, 0.1); padding: 0.2em 0 0.05em; border-radius: 3px; @@ -52,7 +52,7 @@ } pre { - font-family: "Fira Mono", monospace; + font-family: $monospace-fonts; } .hmn-code { diff --git a/src/rawdata/scss/_core.scss b/src/rawdata/scss/_core.scss index 8b0b5d81..4b687931 100644 --- a/src/rawdata/scss/_core.scss +++ b/src/rawdata/scss/_core.scss @@ -136,8 +136,14 @@ hr { max-width: 300px; } +$monospace-fonts: "Fira Mono", monospace; + +.mono { + font-family: $monospace-fonts; +} + article code { - font-family: "Fira Mono", monospace; + font-family: $monospace-fonts; } .big { font-size:120%; } @@ -318,6 +324,10 @@ article code { min-height: $height-5; } +.minh-6 { + min-height: $height-6; +} + .fira { font-family: "Fira Sans", sans-serif; } diff --git a/src/rawdata/scss/_editor.scss b/src/rawdata/scss/_editor.scss index d1c1e5b8..b6ab5bcd 100644 --- a/src/rawdata/scss/_editor.scss +++ b/src/rawdata/scss/_editor.scss @@ -1,3 +1,4 @@ +// TODO: Old and wrong and bad .toolbar { @include usevar('background-color', 'editor-toolbar-background'); @include usevar('border-color', 'editor-toolbar-border-color'); @@ -35,44 +36,10 @@ } } -.editor { - .toolbar { - width:95%; - margin:10px auto; - - select { - font-size:10pt; - border:0px; - - &:hover { - border:0px; - } - - &:focus{ - border:0px; - } - } - - #bold { - font-weight: bold; - } - - #italic { - font-style: italic; - } - - #underline { - text-decoration: underline; - } - - #monospace { - font-family: monospace; - } - - #url { - text-decoration: underline; - font-style: italic; - } +@media #{$breakpoint-not-small} { + #preview-container { + max-height: calc(100vh - 20rem); + overflow: auto; } } diff --git a/src/rawdata/scss/_forum.scss b/src/rawdata/scss/_forum.scss index 14daab4a..e5ccc72e 100644 --- a/src/rawdata/scss/_forum.scss +++ b/src/rawdata/scss/_forum.scss @@ -131,7 +131,7 @@ } .codeblocktable { - font-family: "Fira Mono", monospace; + font-family: $monospace-fonts; font-size:14px; overflow:auto; line-height:1.5em; @@ -406,7 +406,7 @@ li.post-entry { border-width: 1px; border-radius: 2px; - font-family: "Fira Mono", monospace; + font-family: $monospace-fonts; width:49%; box-sizing:border-box; padding: 4px; diff --git a/src/rawdata/scss/tachyons/scss/_variables.scss b/src/rawdata/scss/tachyons/scss/_variables.scss index f3cad387..d4ee6c50 100644 --- a/src/rawdata/scss/tachyons/scss/_variables.scss +++ b/src/rawdata/scss/tachyons/scss/_variables.scss @@ -36,6 +36,7 @@ $height-2: 2rem !default; $height-3: 4rem !default; $height-4: 8rem !default; $height-5: 16rem !default; +$height-6: 32rem !default; $width-1: 1rem !default; $width-2: 2rem !default; $width-3: 4rem !default; diff --git a/src/templates/src/editor.html b/src/templates/src/editor.html index 2ef0e33b..6acb6496 100644 --- a/src/templates/src/editor.html +++ b/src/templates/src/editor.html @@ -1,13 +1,14 @@ {{ template "base.html" . }} {{ define "extrahead" }} + {{/* TODO: These are no longer useful? */}}