Syntax highlighting, reload all notes at once
This commit is contained in:
parent
b6da06df98
commit
abf021a256
|
@ -1 +1,2 @@
|
|||
/build
|
||||
.gowing
|
||||
|
|
|
@ -65,6 +65,11 @@ Add tests if you want. I may get around to it eventually.
|
|||
* Run `build.sh`. It will create the different platform binaries in `build` as
|
||||
well as a `config.yml` sample.
|
||||
|
||||
## Other stuff
|
||||
|
||||
This app uses a custom build of Prism for syntax highlighting. It includes every
|
||||
language that Prism supports as of Feb 2022.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
|
|
|
@ -7,6 +7,10 @@ import draggable from 'vuedraggable'
|
|||
import Note from './components/Note.vue'
|
||||
import NoteSearch from './components/NoteSearch.vue'
|
||||
|
||||
// global Prism object
|
||||
import './prism.js'
|
||||
import './prism.css'
|
||||
|
||||
const results = ref([])
|
||||
const notes = ref([])
|
||||
const searchFocus = ref(+new Date)
|
||||
|
@ -73,6 +77,12 @@ async function loadNoteData(id) {
|
|||
return responseJSON
|
||||
}
|
||||
|
||||
async function loadNotesData(ids) {
|
||||
const response = await fetch(`/api/v1/notes?ids=${ids.join(',')}`)
|
||||
const responseJSON = await response.json()
|
||||
return responseJSON
|
||||
}
|
||||
|
||||
async function loadNote(id) {
|
||||
try {
|
||||
const noteData = await loadNoteData(id)
|
||||
|
@ -153,9 +163,7 @@ onMounted(() => {
|
|||
})
|
||||
|
||||
setInterval(async () => {
|
||||
for (let i = 0; i < notes.value.length; ++i) {
|
||||
await reloadNote(i)
|
||||
}
|
||||
notes.value = await loadNotesData(notes.value.map(n => n.id))
|
||||
}, 5000)
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -2,6 +2,24 @@
|
|||
import { ref, computed, onMounted } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
|
||||
console.log(Prism.languages)
|
||||
|
||||
const MAPPINGS = {
|
||||
golang: 'go'
|
||||
}
|
||||
|
||||
marked.setOptions({
|
||||
highlight: function(code, lang) {
|
||||
if (MAPPINGS[lang]) { lang = MAPPINGS[lang] }
|
||||
|
||||
if (Prism.languages[lang]) {
|
||||
return Prism.highlight(code, Prism.languages[lang], lang)
|
||||
} else {
|
||||
return code
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const props = defineProps({
|
||||
id: String,
|
||||
title: String,
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
/* PrismJS 1.27.0
|
||||
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+abap+abnf+actionscript+ada+agda+al+antlr4+apacheconf+apex+apl+applescript+aql+arduino+arff+asciidoc+aspnet+asm6502+asmatmel+autohotkey+autoit+avisynth+avro-idl+bash+basic+batch+bbcode+bicep+birb+bison+bnf+brainfuck+brightscript+bro+bsl+c+csharp+cpp+cfscript+chaiscript+cil+clojure+cmake+cobol+coffeescript+concurnas+csp+cooklang+coq+crystal+css-extras+csv+cypher+d+dart+dataweave+dax+dhall+diff+django+dns-zone-file+docker+dot+ebnf+editorconfig+eiffel+ejs+elixir+elm+etlua+erb+erlang+excel-formula+fsharp+factor+false+firestore-security-rules+flow+fortran+ftl+gml+gap+gcode+gdscript+gedcom+gherkin+git+glsl+gn+go+go-module+graphql+groovy+haml+handlebars+haskell+haxe+hcl+hlsl+hoon+http+hpkp+hsts+ichigojam+icon+icu-message-format+idris+ignore+inform7+ini+io+j+java+javadoc+javadoclike+javastacktrace+jexl+jolie+jq+jsdoc+js-extras+json+json5+jsonp+jsstacktrace+js-templates+julia+keepalived+keyman+kotlin+kumir+kusto+latex+latte+less+lilypond+liquid+lisp+livescript+llvm+log+lolcode+lua+magma+makefile+markdown+markup-templating+matlab+maxscript+mel+mermaid+mizar+mongodb+monkey+moonscript+n1ql+n4js+nand2tetris-hdl+naniscript+nasm+neon+nevod+nginx+nim+nix+nsis+objectivec+ocaml+opencl+openqasm+oz+parigp+parser+pascal+pascaligo+psl+pcaxis+peoplecode+perl+php+phpdoc+php-extras+plsql+powerquery+powershell+processing+prolog+promql+properties+protobuf+pug+puppet+pure+purebasic+purescript+python+qsharp+q+qml+qore+r+racket+cshtml+jsx+tsx+reason+regex+rego+renpy+rest+rip+roboconf+robotframework+ruby+rust+sas+sass+scss+scala+scheme+shell-session+smali+smalltalk+smarty+sml+solidity+solution-file+soy+sparql+splunk-spl+sqf+sql+squirrel+stan+iecst+stylus+swift+systemd+t4-templating+t4-cs+t4-vb+tap+tcl+tt2+textile+toml+tremor+turtle+twig+typescript+typoscript+unrealscript+uorazor+uri+v+vala+vbnet+velocity+verilog+vhdl+vim+visual-basic+warpscript+wasm+web-idl+wiki+wolfram+wren+xeora+xml-doc+xojo+xquery+yaml+yang+zig&plugins=line-highlight+line-numbers */
|
||||
code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
|
||||
pre[data-line]{position:relative;padding:1em 0 1em 3em}.line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}@media print{.line-highlight{-webkit-print-color-adjust:exact;color-adjust:exact}}.line-highlight:before,.line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}.line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}.line-numbers .line-highlight:after,.line-numbers .line-highlight:before{content:none}pre[id].linkable-line-numbers span.line-numbers-rows{pointer-events:all}pre[id].linkable-line-numbers span.line-numbers-rows>span:before{cursor:pointer}pre[id].linkable-line-numbers span.line-numbers-rows>span:hover:before{background-color:rgba(128,128,128,.2)}
|
||||
pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}
|
File diff suppressed because one or more lines are too long
|
@ -10,7 +10,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/browser"
|
||||
//"github.com/pkg/browser"
|
||||
)
|
||||
|
||||
//go:embed dist/*
|
||||
|
@ -27,6 +27,7 @@ func main() {
|
|||
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
router.HandleFunc("/api/v1/search", searchHandler)
|
||||
router.HandleFunc("/api/v1/notes", notesHandler)
|
||||
router.HandleFunc("/api/v1/note/{id}", noteHandler)
|
||||
|
||||
fmt.Println("starting public file server")
|
||||
|
@ -51,8 +52,10 @@ func main() {
|
|||
fmt.Println("listening on localhost:8181")
|
||||
http.ListenAndServe("localhost:8181", router)
|
||||
|
||||
err = browser.OpenURL("http://localhost:8181")
|
||||
if err != nil {
|
||||
fmt.Println("Unable to open browser, visit http://localhost:8181")
|
||||
}
|
||||
/*
|
||||
err = browser.OpenURL("http://localhost:8181")
|
||||
if err != nil {
|
||||
fmt.Println("Unable to open browser, visit http://localhost:8181")
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -47,3 +50,29 @@ func noteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||
w.Write(body)
|
||||
}
|
||||
|
||||
func notesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("made it")
|
||||
noteIDs := strings.Split(r.URL.Query().Get("ids"), ",")
|
||||
|
||||
notes := []noteResponse{}
|
||||
|
||||
for _, noteID := range noteIDs {
|
||||
response, err := retrieveNote(noteID)
|
||||
|
||||
if err == nil {
|
||||
notes = append(notes, response)
|
||||
}
|
||||
}
|
||||
|
||||
body, err := json.Marshal(notes)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte("Error serializing JSON!"))
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||
w.Write(body)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue