From 61d54a847fe5dd79c945820bba5d42b8e357b4d3 Mon Sep 17 00:00:00 2001 From: bie Date: Thu, 10 Nov 2016 18:49:36 +0100 Subject: THESE TEARS ARE MADE FOR CAULKIN' --- .gitignore | 15 +++++++ TODO | 2 - tears | 2 +- tears.cgi | 121 +++++++++++++++++++++++++++++++++------------------- tears.js | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- tears.rc | 3 ++ 6 files changed, 234 insertions(+), 49 deletions(-) create mode 100644 .gitignore create mode 100644 tears.rc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7dcdea --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +todo +vis +spökvåningen +skriv +oppdater +rediger +ditt +redaksjoner/ +index.html +*~ +stikkord/ +artikler/ +gruppe +lagre +teatime diff --git a/TODO b/TODO index 0230426..299fdfc 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ Med en gang: > Forside - > Tags (tvang!) - > Lupin må kunne brukes som lua-bibliotek > Skille mellom gamle og nye artikler > Templates til lupin (artikkel, anmeldelse, reprise / sending, om redaksjon) > Oversiktssider diff --git a/tears b/tears index cf46689..cedbffa 100755 --- a/tears +++ b/tears @@ -1,6 +1,6 @@ #!/usr/bin/env bash -LINKS="ditt gruppe lagre oppdater rediger skriv teatime todo" +LINKS="ditt gruppe lagre oppdater rediger skriv teatime todo vis" case $1 in prepare) diff --git a/tears.cgi b/tears.cgi index 6698f07..ebf246f 100755 --- a/tears.cgi +++ b/tears.cgi @@ -1,10 +1,10 @@ -#!/usr/local/bin/haserl --shell=/bin/bash +#!/usr/bin/haserl --shell=/bin/bash <% -VERSION=0.1 -BASE="/~bie/tears" -HOST="low.radionova.no" +VERSION=0.4 +BASE="/tears" +HOST="zanthia.radionova.no" path=$(pdecode <<<"${PATH_INFO#/}") @@ -15,11 +15,11 @@ error() { } irc() { - teatime -c '#radionova' "$1" + /opt/bin/birk -c radionova "$1" } byline() { - echo # noe som fungerer både på lunix og bsd her + echo "skrevet av $(ls -ld $1 | awk '{print $3}')" } info() { @@ -27,43 +27,70 @@ info() { } link() { - [ "$BASE/$2" = $REQUEST_URI ] && echo "$1" || echo "$1" + local raw=${REQUEST_URI%\?*} + local clean="/${raw%/}" + local rawt="$BASE/$2" + local cleant="/${rawt%/}" + [ $cleant = $clean ] && echo "$1" || echo "$1" } qlink() { text="$1" && url="$BASE/$2" && shift 2 - IFS=\& && echo -n "$text" + local IFS=\& && echo -ne "$text\n" } redirect() { - echo "Content-Type: text/html" + echo -e "Content-Type: text/html; charset=utf-8" echo -e "Location: https://$HOST$1\n" echo "٩(͡๏̯͡๏)۶>" } +stikkordsøk() { + [ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return + echo "
" + echo "

stikkordsøk" + echo "
" + echo "" + echo "

" +} + kalender() { [ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return echo "

for mye? reis i tid…" IFS=- read y m d <<<"$GET_dato" + n=0 + [ -n "$GET_stikkord" ] && n=1 if [ -z "$y" ]; then - for directory in $(cut -d / -f 2 | sort | uniq); do + for directory in $(cut -d / -f $((n + 2)) | sort | uniq); do year=$(basename $directory) - echo "$year" + qlink "$year" "$action/$path" "dato=$year" "stikkord=$GET_stikkord" done elif [ -z "$m" ]; then - echo "$y
" - for directory in $(cut -d / -f 3 | sort | uniq); do + echo "" + qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + echo "
" + for directory in $(cut -d / -f $((n + 3)) | sort | uniq); do month=$(basename $directory) - echo "$month" + qlink "$month" "$action/$path" "dato=$y-$month" "stikkord=$GET_stikkord" done elif [ -z "$d" ]; then - echo "$y/$m
" - for directory in $(cut -d / -f 4 | sort | uniq); do + echo "" + qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + echo "/" + qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord" + echo "
" + for directory in $(cut -d / -f $((n + 4)) | sort | uniq); do day=$(basename $directory) - echo "$day" + qlink "$day" "$action/$path" "dato=$y-$m-$day" "stikkord=$GET_stikkord" done else - echo "$y/$m/$d" + echo "" + qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + echo "/" + qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord" + echo "/" + qlink "$d" "$action/$path" "dato=$y-$m" "stikkord=$GET_stikkord" + echo "
" fi } @@ -83,6 +110,7 @@ meny() { link "$group" "gruppe/$group" done kalender + stikkordsøk echo "

kos deg! ٩(͡๏̯͡๏)۶" echo "

" - for tag in $2; do - echo "-- sjekke om tag $tag er ok --" - echo "
" - echo ln -s "$1" "tags/$tag/$(tr / - <<<$1)" - echo "
" +stikk() { + find -L stikkord -samefile "$1" -delete + for ord in $2; do + local path="stikkord/$ord/${1#artikler/}" + mkdir -p "$(dirname $path)" + ln -s "../../../../../$1" "$path" done } @@ -124,9 +153,8 @@ skjema() { [ ! -w "$1" ] && echo "

du har ikke skrivetilgang" && exit echo "

" lupin -f <$1 - echo "

" - echo "" - tag "$1" "ok test haha" + echo "

" + echo "" echo "

" echo "

" echo "

$(info $1)" @@ -155,6 +183,8 @@ oppdater() { [ ! -f "$1" ] && error "finner ikke $1" [ ! -w "$1" ] && error "ikke skrivetilgang til $1" [ -z "$POST_title" ] && error "ingen overskrift" + [ -z "$POST_stikkord" ] && error "ingen stikkord" + stikk "$1" "$POST_stikkord" lupin -l -e >$1 irc "$(whoami) redigerte $POST_title" redirect "$BASE/rediger/$path" @@ -162,13 +192,11 @@ oppdater() { kort() { IFS=/. read -r type y m d hhmm slug ext <<< "$1" - ( - read -r tittel - echo "

$tittel

" "

$(byline $1), $y/$m/$d" - [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1") - [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1") - [ -z "$2" ] && head -1 | marxup - || marxup - - ) < $1 + lupin -t -h <$1 + echo "

$(byline $1), $y/$m/$d" + [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1") + [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1") + lupin -s -h <$1 } forbered() { @@ -202,8 +230,13 @@ umask 0022 groups=$(groups | tr " " "\n" | sort) available=$(comm -12 - <(ls redaksjoner | sort) <<<"$groups") action=$(basename $SCRIPT_FILENAME) -kilde="artikler/$(sed 's|-|/|g' <<<$GET_dato)" -finder="find $kilde -type f" +if [[ "$action" == rediger && $path == stikkord/* ]]; then + redirect "$BASE/rediger/artikler/${path#stikkord/*/}" +fi +mappe="artikler" +[ -n "$GET_stikkord" ] && mappe="stikkord/$GET_stikkord" +kilde="$mappe/$(sed 's|-|/|g' <<<$GET_dato)" +finder="find -L $kilde -type f" [ "$action" = gruppe ] && finder="$finder -group $path" [ "$action" = ditt ] && finder="$finder -user $REMOTE_USER" [ "$REQUEST_METHOD" = GET ] && $finder | meny @@ -214,8 +247,8 @@ case $action in vis) vis $path;; lagre) lagre;; oppdater) oppdater $path;; - teatime) irc "$(whoami) <3 teatime"; echo "


";; - spökvåningen) echo "

spök";; + teatime) irc "$(whoami) <3 teatime"; echo "


";; + spökvåningen) echo "

";; todo) echo "

$(cat TODO)
";; esac %> diff --git a/tears.js b/tears.js index fd29a3a..9f459e4 100644 --- a/tears.js +++ b/tears.js @@ -24,12 +24,116 @@ function pick(src) { } } + +function insert(text) { + var t = document.getElementsByName('tekst')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + t.value = t.value.substring(0, pos) + text + t.value.substring(end, t.value.length); + } + var cpos = t.selectionStart; + t.setSelectionRange(cpos, cpos); + t.focus(); +} + +function wrap(prefix, postfix) { + var t = document.getElementsByName('tekst')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + var n = t.value.indexOf("\n", pos); + if(n > 0 && n < end) end = n; + t.value = t.value.substring(0, pos) + prefix + t.value.substring(pos, end) + postfix + t.value.substring(end, t.value.length); + } + var cpos = end + prefix.length + postfix.length; + t.setSelectionRange(cpos, cpos); + t.focus(); +} + +function prepend(text) { + var t = document.getElementsByName('tekst')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + for(;pos < end; pos++) { + if(t.value.charAt(pos) != "\n") break; + } + for(;end > pos; end--) { + if(t.value.charAt(end - 1) != "\n") break; + } + var quote = ""; + var cpos = end; + if(t.value.charAt(pos - 1) != "\n") { + quote += "\n"; + cpos += 1; + } + if(pos == end) { + quote += text; + cpos += text.length; + } else { + var lines = t.value.substring(pos, end).split("\n"); + for(var i=0; i < lines.length; i++) { + quote += text + lines[i] + "\n"; + cpos += text.length; + } + quote = quote.slice(0, -1); + } + t.value = t.value.substring(0, pos) + quote + t.value.substring(end, t.value.length); + } + t.setSelectionRange(cpos, cpos); + t.focus(); +} + +function marxup_bold(e) { + wrap("*", "*"); +} + +function marxup_header(e) { + prepend("= "); +} + +function marxup_italics(e) { + wrap("_", "_"); +} + +function marxup_small(e) { + wrap("~", "~"); +} + +function marxup_link(e) { + wrap("[", "]"); +} + +function marxup_quote(e) { + prepend("> "); +} + +function marxup_list(e) { + prepend("* "); +} + +function button(node, html, fun) { + var a = document.createElement("a"); + a.innerHTML = html; + a.href = "#"; + a.onclick = fun; + node.parentNode.insertBefore(a, node.nextSibling); +} + +function orz(src) { + insert("\n{" + src.replace(".t.jpg", "") + "}\n"); +} + document.addEventListener("DOMContentLoaded", function(e) { var field = document.getElementsByName('publisert')[0]; if(field) { new Pikaday({ field: field, format: 'YYYY-MM-DD' }); } - +/* var els = document.getElementsByClassName('orz'); for(var i=0; i < els.length; i++) { els[i].onclick = function(e) { @@ -38,5 +142,37 @@ document.addEventListener("DOMContentLoaded", function(e) { return false; } } -}, false); +*/ + + var title = document.getElementsByTagName('h1')[0]; + var headers = document.getElementsByTagName("h2"); + if(headers.length > 0) { + var menu = document.createElement("div"); menu.className = 'magisk meny'; + for(var i = 0; i < headers.length; i++) { + var a = document.createElement("a"); + var id = "h-" + i; headers[i].id = id; a.href = "#" + id; + a.textContent = headers[i].textContent; + menu.appendChild(a); + menu.appendChild(document.createElement("br")); + } + title.parentNode.insertBefore(menu, title.nextSibling); + } + +// var orz = document.getElementById('orz'); + var orz = document.getElementsByClassName('orz')[0]; + if(orz) { + orz.onclick = function(e) { + window.open("/orz"); + return false; + } + button(orz, "> sitat", marxup_quote); + button(orz, "* liste", marxup_list); + button(orz, "[lenke]", marxup_link); + button(orz, "_kursiv_", marxup_italics); + button(orz, "*fet*", marxup_bold); + button(orz, "liten", marxup_small); + button(orz, "= overskrift", marxup_header); + } +}); + diff --git a/tears.rc b/tears.rc new file mode 100644 index 0000000..308bc0f --- /dev/null +++ b/tears.rc @@ -0,0 +1,3 @@ +byline() { + stat -c 'skrevet av %U for %G' $1 +} -- cgit v1.0