From f5ed6ec89676191df87b3186e05068c02c3b12cb Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Mon, 6 Dec 2021 23:20:12 -0600 Subject: [PATCH] Add live markdown preview to the description editor --- src/db/query_builder.go | 6 +- src/hmnurl/hmnurl_test.go | 6 +- src/hmnurl/urls.go | 6 +- src/templates/src/editor.html | 120 +++--------------- src/templates/src/include/header.html | 6 +- .../src/include/markdown_previews.html | 106 ++++++++++++++++ .../{editorpreviews.js => markdown_worker.js} | 23 ++-- src/templates/src/project_edit.html | 70 +++++++--- src/website/projects.go | 30 +++-- src/website/routes.go | 4 +- 10 files changed, 221 insertions(+), 156 deletions(-) create mode 100644 src/templates/src/include/markdown_previews.html rename src/templates/src/{editorpreviews.js => markdown_worker.js} (60%) diff --git a/src/db/query_builder.go b/src/db/query_builder.go index 1f794c9..80a687f 100644 --- a/src/db/query_builder.go +++ b/src/db/query_builder.go @@ -14,9 +14,9 @@ type QueryBuilder struct { Adds the given SQL and arguments to the query. Any occurrences of `$?` will be replaced with the correct argument number. -foo $? bar $? baz $? -foo ARG1 bar ARG2 baz $? -foo ARG1 bar ARG2 baz ARG3 + foo $? bar $? baz $? + foo ARG1 bar ARG2 baz $? + foo ARG1 bar ARG2 baz ARG3 */ func (qb *QueryBuilder) Add(sql string, args ...interface{}) { numPlaceholders := strings.Count(sql, "$?") diff --git a/src/hmnurl/hmnurl_test.go b/src/hmnurl/hmnurl_test.go index 2832c92..77dba56 100644 --- a/src/hmnurl/hmnurl_test.go +++ b/src/hmnurl/hmnurl_test.go @@ -298,12 +298,12 @@ func TestProjectCSS(t *testing.T) { AssertRegexMatch(t, BuildProjectCSS("000000"), RegexProjectCSS, nil) } -func TestEditorPreviewsJS(t *testing.T) { - AssertRegexMatch(t, BuildEditorPreviewsJS(), RegexEditorPreviewsJS, nil) +func TestMarkdownWorkerJS(t *testing.T) { + AssertRegexMatch(t, BuildMarkdownWorkerJS(), RegexMarkdownWorkerJS, nil) } func TestAPICheckUsername(t *testing.T) { - AssertRegexmatch(t, BuildAPICheckUsername(), RegexAPICheckUsername, nil) + AssertRegexMatch(t, BuildAPICheckUsername(), RegexAPICheckUsername, nil) } func TestPublic(t *testing.T) { diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index dfb8cc9..4e8e8ba 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -702,11 +702,11 @@ func BuildProjectCSS(color string) string { return Url("/assets/project.css", []Q{{"color", color}}) } -var RegexEditorPreviewsJS = regexp.MustCompile("^/assets/editorpreviews.js$") +var RegexMarkdownWorkerJS = regexp.MustCompile("^/assets/markdown_worker.js$") -func BuildEditorPreviewsJS() string { +func BuildMarkdownWorkerJS() string { defer CatchPanic() - return Url("/assets/editorpreviews.js", nil) + return Url("/assets/markdown_worker.js", nil) } var RegexS3Asset *regexp.Regexp diff --git a/src/templates/src/editor.html b/src/templates/src/editor.html index 6bf5937..580f6d9 100644 --- a/src/templates/src/editor.html +++ b/src/templates/src/editor.html @@ -1,11 +1,9 @@ {{ template "base.html" . }} {{ define "extrahead" }} - + {{ template "markdown_previews.html" . }} + - {{ end }} {{ define "content" }} -
+
{{ if .Editing }}

Edit {{ .ProjectSettings.Name }}

{{ else }} @@ -28,20 +37,12 @@
-
- {{/* TODO(asaf): Should this be admin only??*/}} -
Hidden:
-
- - -
-
Owners:
@@ -72,12 +73,6 @@
Admin settings
-
-
Slug:
-
- -
-
Official:
@@ -85,12 +80,27 @@
+
+
Hidden:
+
+ + +
+
+
+
Slug:
+
+ +
Has no effect for personal projects. Personal projects have a slug derived from the title.
+
If you change this, make sure to change DNS too!
+
+
Featured:
-
Bump to the top of the project index and show in the carousel.
+
Bump to the top of the project index and show in the carousel. Has no effect for personal projects.
{{ end }} @@ -118,10 +128,11 @@
Full description:
- - {{/* TODO(asaf): Replace with the full editor */}} +
Preview:
+
@@ -164,7 +175,7 @@