Add editor's notes

This commit is contained in:
Ben Visness 2022-09-10 10:25:33 -05:00
parent 9ffc64fcf3
commit 6cec54f8cc
11 changed files with 42 additions and 14 deletions

Binary file not shown.

View File

@ -1176,7 +1176,7 @@ img, video {
.br2, .post-content code, .post-content pre > code, .post-content pre.hmn-code { .br2, .post-content code, .post-content pre > code, .post-content pre.hmn-code {
border-radius: 0.25rem; } border-radius: 0.25rem; }
.br3, .edu-resource { .br3, .edu-article .edu-resource {
border-radius: 0.5rem; } border-radius: 0.5rem; }
.br4 { .br4 {
@ -4602,7 +4602,7 @@ code, .code {
.pa2, .tab, header .root-item > a, header .submenu > a { .pa2, .tab, header .root-item > a, header .submenu > a {
padding: 0.5rem; } padding: 0.5rem; }
.pa3, .edu-resource, header #login-popup { .pa3, .edu-article .edu-resource, header #login-popup {
padding: 1rem; } padding: 1rem; }
.pa4 { .pa4 {
@ -7426,7 +7426,7 @@ article code {
border-color: #ccc; border-color: #ccc;
border-color: var(--theme-color-dimmest); } border-color: var(--theme-color-dimmest); }
.bg--dim, .post-content code, .post-content pre > code, .post-content pre.hmn-code, .edu-resource { .bg--dim, .post-content code, .post-content pre > code, .post-content pre.hmn-code, .edu-article .edu-resource {
background-color: #f0f0f0; background-color: #f0f0f0;
background-color: var(--dim-background); } background-color: var(--dim-background); }
@ -8301,6 +8301,9 @@ nav.timecodes {
text-align: center; text-align: center;
margin: 10px 0; } margin: 10px 0; }
.edu-article .note {
color: red; }
form { form {
margin: 0; } margin: 0; }

View File

@ -28,13 +28,13 @@ func QFromURL(u *url.URL) []Q {
} }
var baseUrlParsed url.URL var baseUrlParsed url.URL
var cacheBust string var cacheBustVersion string
var S3BaseUrl string var S3BaseUrl string
var isTest bool var isTest bool
func init() { func init() {
SetGlobalBaseUrl(config.Config.BaseUrl) SetGlobalBaseUrl(config.Config.BaseUrl)
SetCacheBust(fmt.Sprint(time.Now().Unix())) SetCacheBustVersion(fmt.Sprint(time.Now().Unix()))
SetS3BaseUrl(config.Config.DigitalOcean.AssetsPublicUrlRoot) SetS3BaseUrl(config.Config.DigitalOcean.AssetsPublicUrlRoot)
} }
@ -50,8 +50,8 @@ func SetGlobalBaseUrl(fullBaseUrl string) {
baseUrlParsed = *parsed baseUrlParsed = *parsed
} }
func SetCacheBust(newCacheBust string) { func SetCacheBustVersion(newCacheBustVersion string) {
cacheBust = newCacheBust cacheBustVersion = newCacheBustVersion
} }
func SetS3BaseUrl(base string) { func SetS3BaseUrl(base string) {

View File

@ -837,7 +837,7 @@ func BuildPublic(filepath string, cachebust bool) string {
} }
var query []Q var query []Q
if cachebust { if cachebust {
query = []Q{{"v", cacheBust}} query = []Q{{"v", cacheBustVersion}}
} }
return Url(builder.String(), query) return Url(builder.String(), query)
} }

View File

@ -63,6 +63,14 @@ var ggcodeTags = map[string]ggcodeRenderer{
} }
return nil return nil
}, },
"note": func(w util.BufWriter, n *ggcodeNode, entering bool) error {
if entering {
w.WriteString(`<span class="note">`)
} else {
w.WriteString(`</span>`)
}
return nil
},
} }
// ---------------------- // ----------------------

View File

@ -1,3 +1,9 @@
.edu-resource { .edu-article {
@extend .pa3, .bg--dim, .br3; .edu-resource {
@extend .pa3, .bg--dim, .br3;
}
.note {
color: red;
}
} }

View File

@ -108,7 +108,7 @@
</div> </div>
{{ end }} {{ end }}
</form> </form>
<div id="preview-container" class="post post-preview mathjax flex-fair-ns overflow-auto mv3 mv0-ns ml3-ns pa3 br3 bg--dim"> <div id="preview-container" class="post post-preview mathjax flex-fair-ns overflow-auto mv3 mv0-ns ml3-ns pa3 br3 bg--dim {{ .PreviewClass }}">
<div id="preview" class="post-content"></div> <div id="preview" class="post-content"></div>
</div> </div>
<input type="file" multiple name="file_input" id="file_input" class="dn" />{{/* NOTE(asaf): Placing this outside the form to avoid submitting it to the server by accident */}} <input type="file" multiple name="file_input" id="file_input" class="dn" />{{/* NOTE(asaf): Placing this outside the form to avoid submitting it to the server by accident */}}

View File

@ -9,7 +9,7 @@
</div> </div>
{{ end }} {{ end }}
<div class="flex"> <div class="flex">
<div class="flex-grow-1 post-content"> <div class="edu-article flex-grow-1 post-content">
{{ .Article.Content }} {{ .Article.Content }}
</div> </div>
<div class="ml3 flex-shrink-0 w5"> <div class="ml3 flex-shrink-0 w5">

View File

@ -1,4 +1,4 @@
importScripts('/public/go_wasm_exec.js'); importScripts('{{ static "go_wasm_exec.js" }}');
// wowee good javascript yeah // wowee good javascript yeah
const global = Function('return this')(); const global = Function('return this')();
@ -18,7 +18,7 @@ onmessage = ({ data }) => {
} }
const go = new Go(); const go = new Go();
WebAssembly.instantiateStreaming(fetch('/public/parsing.wasm'), go.importObject) WebAssembly.instantiateStreaming(fetch('{{ static "parsing.wasm" }}'), go.importObject)
.then(result => { .then(result => {
go.run(result.instance); // don't await this; we want it to be continuously running go.run(result.instance); // don't await this; we want it to be continuously running
wasmLoaded = true; wasmLoaded = true;

View File

@ -4,8 +4,10 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"net/url" "net/url"
"regexp"
"time" "time"
"git.handmade.network/hmn/hmn/src/db" "git.handmade.network/hmn/hmn/src/db"
@ -58,6 +60,8 @@ func EducationGlossary(c *RequestContext) ResponseData {
return res return res
} }
var reEduEditorsNote = regexp.MustCompile(`<span\s*class="note".*?>.*?</span>`)
func EducationArticle(c *RequestContext) ResponseData { func EducationArticle(c *RequestContext) ResponseData {
type articleData struct { type articleData struct {
templates.BaseData templates.BaseData
@ -87,6 +91,11 @@ func EducationArticle(c *RequestContext) ResponseData {
{Name: article.Title, Url: hmnurl.BuildEducationArticle(article.Slug)}, {Name: article.Title, Url: hmnurl.BuildEducationArticle(article.Slug)},
} }
// Remove editor's notes
if c.CurrentUser == nil || !c.CurrentUser.CanAuthorEducation() {
tmpl.Article.Content = template.HTML(reEduEditorsNote.ReplaceAllLiteralString(string(tmpl.Article.Content), ""))
}
var res ResponseData var res ResponseData
res.MustWriteTemplate("education_article.html", tmpl, c.Perf) res.MustWriteTemplate("education_article.html", tmpl, c.Perf)
return res return res
@ -311,6 +320,7 @@ func getEditorDataForEduArticle(
MaxFileSize: AssetMaxSize(currentUser), MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(), UploadUrl: urlContext.BuildAssetUpload(),
ShowEduOptions: true, ShowEduOptions: true,
PreviewClass: "edu-article",
ParserName: "parseMarkdownEdu", ParserName: "parseMarkdownEdu",
} }

View File

@ -49,6 +49,7 @@ type editorData struct {
EditInitialContents string EditInitialContents string
PostReplyingTo *templates.Post PostReplyingTo *templates.Post
ShowEduOptions bool ShowEduOptions bool
PreviewClass string
ParserName string ParserName string
MaxFileSize int MaxFileSize int