2021-03-25 16:02:55 +01:00
|
|
|
|
<script>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
import SpTitle from "./SpTitle.svelte";
|
|
|
|
|
import SpTiers from "./SpTiers.svelte";
|
|
|
|
|
import SpKeys from "./SpKeys.svelte";
|
|
|
|
|
import SpCandidates from "./SpCandidates.svelte";
|
2021-06-18 13:20:54 +02:00
|
|
|
|
import SpJournal from "./SpJournal.svelte";
|
2021-06-08 12:39:07 +02:00
|
|
|
|
import { onMount } from "svelte";
|
|
|
|
|
let v = "loading...";
|
|
|
|
|
let relpath = "";
|
|
|
|
|
let relpermalink = "";
|
|
|
|
|
let protocol = "";
|
|
|
|
|
let title = "Foo bar";
|
2021-08-18 15:00:45 +02:00
|
|
|
|
let hases = [];
|
|
|
|
|
let hasesCandidates = [];
|
|
|
|
|
let frontmatter = {};
|
|
|
|
|
frontmatter["triad"] = [];
|
2021-08-22 00:34:00 +02:00
|
|
|
|
frontmatter["ascription"] = [];
|
2021-06-08 12:39:07 +02:00
|
|
|
|
frontmatter["notsand"] = [];
|
2021-06-02 02:02:20 +02:00
|
|
|
|
|
2021-06-08 12:39:07 +02:00
|
|
|
|
function keyUp(e) {
|
|
|
|
|
if (e.key == "Escape") {
|
|
|
|
|
window.history.back();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-02 02:02:20 +02:00
|
|
|
|
|
2021-08-21 12:28:52 +02:00
|
|
|
|
function reckonHasesCandidates() {
|
|
|
|
|
return diffArrr(hases, [
|
|
|
|
|
...frontmatter["triad"].map((t) => {
|
|
|
|
|
return t.fmKey;
|
|
|
|
|
}),
|
2021-08-22 00:34:00 +02:00
|
|
|
|
...frontmatter["ascription"].map((t) => {
|
2021-08-21 12:28:52 +02:00
|
|
|
|
return t.fmKey;
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 01:38:27 +02:00
|
|
|
|
function diffArrr(arr, arrr) {
|
2021-06-08 12:39:07 +02:00
|
|
|
|
let diff = new Set(arr);
|
2021-04-24 01:14:16 +02:00
|
|
|
|
for (let e of arrr) {
|
2021-06-08 12:39:07 +02:00
|
|
|
|
diff.delete(e);
|
2021-04-24 01:14:16 +02:00
|
|
|
|
}
|
2021-06-08 12:39:07 +02:00
|
|
|
|
return Array.from(diff);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 12:28:52 +02:00
|
|
|
|
function newTier(fmKeyType, fmKey, fmValue) {
|
|
|
|
|
let tiers = [];
|
|
|
|
|
let candidates = [];
|
|
|
|
|
if (fmKey == "_new") {
|
2021-08-22 00:34:00 +02:00
|
|
|
|
hasesCandidates = [...new Set(reckonHasesCandidates())];
|
2021-08-19 13:08:03 +02:00
|
|
|
|
if (hasesCandidates.length > 0) {
|
2021-08-22 00:34:00 +02:00
|
|
|
|
fmKey = hasesCandidates[0];
|
2021-08-19 13:08:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-18 15:00:45 +02:00
|
|
|
|
|
2021-08-21 12:28:52 +02:00
|
|
|
|
if (fmKey != "_new") {
|
|
|
|
|
if (fmValue) {
|
2021-08-22 00:34:00 +02:00
|
|
|
|
METASP[fmKey].tiers.forEach((t) => {
|
|
|
|
|
if (fmValue.includes(t.file)) {
|
|
|
|
|
tiers.push(t);
|
|
|
|
|
} else {
|
|
|
|
|
candidates.push(t);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-08-19 13:08:03 +02:00
|
|
|
|
} else {
|
2021-08-21 12:28:52 +02:00
|
|
|
|
tiers = [];
|
|
|
|
|
candidates = METASP[fmKey].tiers;
|
2021-08-19 13:08:03 +02:00
|
|
|
|
}
|
2021-08-21 12:28:52 +02:00
|
|
|
|
frontmatter[fmKeyType].push({
|
|
|
|
|
fmKey: fmKey,
|
|
|
|
|
tiers: tiers,
|
|
|
|
|
candidates: [...new Set(candidates)],
|
|
|
|
|
});
|
|
|
|
|
frontmatter = { ...frontmatter };
|
2021-08-19 13:08:03 +02:00
|
|
|
|
}
|
2021-08-22 00:34:00 +02:00
|
|
|
|
hasesCandidates = [...new Set(reckonHasesCandidates())];
|
|
|
|
|
toggleNewTiersButtons();
|
2021-06-08 12:39:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 01:11:00 +02:00
|
|
|
|
function loadHugoPageMetadata(editHash) {
|
2021-08-18 15:00:45 +02:00
|
|
|
|
let el = document.createElement("script");
|
2021-06-08 12:39:07 +02:00
|
|
|
|
el.onload = () => {
|
|
|
|
|
v = repo.content;
|
|
|
|
|
if (v.startsWith("\n")) {
|
|
|
|
|
v = v.substring(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
relpath = repo.path;
|
|
|
|
|
relpermalink = repo.relpermalink;
|
|
|
|
|
protocol = document.location.protocol.substring(0, 4);
|
2021-08-18 15:00:45 +02:00
|
|
|
|
const notSelf = Object.entries(METASP).filter((n) => n[1].singular == relpath.split("/")[0])[0][0];
|
|
|
|
|
hases = Object.keys(METASP).filter((k) => k != notSelf);
|
2021-06-08 12:39:07 +02:00
|
|
|
|
Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => {
|
|
|
|
|
let fmKeyType = "";
|
|
|
|
|
if (fmKey.toLowerCase().startsWith("has_")) {
|
|
|
|
|
if (hases.includes(fmKey.substr(4))) {
|
|
|
|
|
fmKeyType = "triad";
|
|
|
|
|
fmKey = fmKey.substr(4);
|
|
|
|
|
}
|
|
|
|
|
} else if (hases.includes(fmKey.toLowerCase())) {
|
2021-08-22 00:34:00 +02:00
|
|
|
|
fmKeyType = "ascription";
|
2021-06-08 12:39:07 +02:00
|
|
|
|
} else if (["abstract", "keywords"].includes(fmKey.toLowerCase())) {
|
|
|
|
|
fmKeyType = "journal";
|
|
|
|
|
} else {
|
|
|
|
|
fmKeyType = "notsand";
|
|
|
|
|
}
|
2021-04-28 17:09:45 +02:00
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
if (["triad", "ascription"].includes(fmKeyType)) {
|
2021-06-08 12:39:07 +02:00
|
|
|
|
if (Array.isArray(fmValue)) {
|
2021-08-18 15:00:45 +02:00
|
|
|
|
newTier(fmKeyType, fmKey, fmValue);
|
2021-06-08 12:39:07 +02:00
|
|
|
|
}
|
|
|
|
|
} else if (fmKeyType == "journal") {
|
|
|
|
|
frontmatter["journal"] || (frontmatter["journal"] = []);
|
2021-06-18 13:20:54 +02:00
|
|
|
|
if (Array.isArray(fmValue)) {
|
|
|
|
|
let fmValueArray = [];
|
|
|
|
|
fmValue.forEach((v) => fmValueArray.push(v));
|
|
|
|
|
frontmatter[fmKeyType].push({ fmKey: fmKey, fmValue: fmValueArray });
|
|
|
|
|
} else {
|
|
|
|
|
frontmatter[fmKeyType].push({ fmKey: fmKey, fmValue: fmValue });
|
|
|
|
|
}
|
2021-06-08 12:39:07 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2021-08-18 15:00:45 +02:00
|
|
|
|
hasesCandidates = reckonHasesCandidates();
|
|
|
|
|
const tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
|
2021-06-08 12:39:07 +02:00
|
|
|
|
title = repo.frontmatter[tkey];
|
2021-08-18 15:00:45 +02:00
|
|
|
|
|
2021-08-21 12:28:52 +02:00
|
|
|
|
toggleNewTiersButtons();
|
2021-06-08 12:39:07 +02:00
|
|
|
|
};
|
2021-08-12 01:11:00 +02:00
|
|
|
|
el.src = `../js/repo/${editHash}.js`;
|
2021-06-08 12:39:07 +02:00
|
|
|
|
document.body.appendChild(el);
|
|
|
|
|
}
|
2021-06-02 02:02:20 +02:00
|
|
|
|
|
2021-06-08 12:39:07 +02:00
|
|
|
|
function addToCandidatesRemoveFromTiers(arrgs) {
|
2021-08-18 15:00:45 +02:00
|
|
|
|
const [fmKeyType, index, fmKey, tier] = arrgs.detail;
|
2021-06-08 12:39:07 +02:00
|
|
|
|
frontmatter[fmKeyType][index]["fmKey"] = fmKey;
|
|
|
|
|
frontmatter[fmKeyType][index]["tiers"] = frontmatter[fmKeyType][index]["tiers"].filter(
|
|
|
|
|
(t) => t !== tier
|
|
|
|
|
);
|
|
|
|
|
frontmatter[fmKeyType][index]["candidates"] = [...frontmatter[fmKeyType][index]["candidates"], tier];
|
|
|
|
|
}
|
2021-06-02 02:02:20 +02:00
|
|
|
|
|
2021-06-08 12:39:07 +02:00
|
|
|
|
function addToTiersRemoveFromCandidates(arrgs) {
|
2021-08-18 15:00:45 +02:00
|
|
|
|
const [fmKeyType, index, , value] = arrgs.detail;
|
2021-06-08 12:39:07 +02:00
|
|
|
|
const tier = frontmatter[fmKeyType][index]["candidates"].filter((t) => t.file == value);
|
|
|
|
|
if (tier.length > 0) {
|
|
|
|
|
frontmatter[fmKeyType][index]["tiers"] = [...frontmatter[fmKeyType][index]["tiers"], tier[0]];
|
|
|
|
|
frontmatter[fmKeyType][index]["candidates"] = frontmatter[fmKeyType][index]["candidates"].filter(
|
|
|
|
|
(t) => t != tier[0]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
function fmItemDottedBorder(e) {
|
|
|
|
|
e.target.parentNode.parentNode.style.border = "2px #ff000075 dotted";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fmItemNoBorder(e) {
|
|
|
|
|
e.target.parentNode.parentNode.style.border = "0px";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeTier(fmKey, fmValue) {
|
|
|
|
|
frontmatter[fmKey] = frontmatter[fmKey].filter((v) => v["fmKey"] != fmValue["fmKey"]);
|
|
|
|
|
toggleNewTiersButtons();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 12:39:07 +02:00
|
|
|
|
function toggleFold() {
|
|
|
|
|
let e = document.getElementById("frontmatter");
|
|
|
|
|
if (e && e.classList.contains("fmHidden")) {
|
|
|
|
|
e.classList.remove("fmHidden");
|
|
|
|
|
e.classList.add("fmShown");
|
|
|
|
|
} else if (e && e.classList.contains("fmShown")) {
|
|
|
|
|
e.classList.remove("fmShown");
|
|
|
|
|
e.classList.add("fmHidden");
|
|
|
|
|
}
|
2021-06-18 13:20:54 +02:00
|
|
|
|
let i = document.getElementById("fmicon");
|
|
|
|
|
if (i && i.classList.contains("fmCollapse")) {
|
|
|
|
|
i.classList.remove("fmCollapse");
|
|
|
|
|
i.classList.add("fmExpand");
|
|
|
|
|
} else if (i && i.classList.contains("fmExpand")) {
|
|
|
|
|
i.classList.remove("fmExpand");
|
|
|
|
|
i.classList.add("fmCollapse");
|
|
|
|
|
}
|
2021-06-08 12:39:07 +02:00
|
|
|
|
}
|
2021-04-15 00:55:21 +02:00
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
function toggleNewTiersButtons() {
|
|
|
|
|
hasesCandidates = [...new Set(reckonHasesCandidates())];
|
2021-08-18 15:00:45 +02:00
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
if (hasesCandidates.length == 0) {
|
|
|
|
|
document.querySelectorAll(".newtiers").forEach((button) => {
|
|
|
|
|
button.style.display = "none";
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
document.querySelectorAll(".newtiers").forEach((button) => {
|
|
|
|
|
button.style.display = "block";
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-08-18 15:00:45 +02:00
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
const ct = Object.entries(frontmatter).filter((i) => i[1].length == 0 && i[0] == "triad")[0];
|
|
|
|
|
if (!ct) {
|
|
|
|
|
document.getElementById("newtriad").style.display = "none";
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-18 15:00:45 +02:00
|
|
|
|
|
|
|
|
|
function dispatchHash() {
|
|
|
|
|
const searchParams = new URLSearchParams(location.search);
|
|
|
|
|
const editHash = searchParams.get("edit");
|
|
|
|
|
if (editHash) {
|
|
|
|
|
loadHugoPageMetadata(editHash);
|
|
|
|
|
} else {
|
|
|
|
|
let newPage = searchParams.get("new");
|
2021-08-22 00:34:00 +02:00
|
|
|
|
console.log({ newPage });
|
2021-08-18 15:00:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
dispatchHash();
|
|
|
|
|
// loadHugoPageMetadata();
|
2021-08-22 00:34:00 +02:00
|
|
|
|
console.dir({ frontmatter });
|
2021-08-18 15:00:45 +02:00
|
|
|
|
});
|
|
|
|
|
|
2021-08-22 00:34:00 +02:00
|
|
|
|
$: hashChanged = () => dispatchHash();
|
2021-03-25 16:02:55 +01:00
|
|
|
|
</script>
|
|
|
|
|
|
2021-08-12 01:11:00 +02:00
|
|
|
|
<svelte:window on:keyup={keyUp} on:hashchange={hashChanged} />
|
2021-03-25 16:02:55 +01:00
|
|
|
|
<main id="sandpoints">
|
|
|
|
|
<form>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
<div class="formgrid">
|
|
|
|
|
<SpTitle {relpath} {title} />
|
|
|
|
|
</div>
|
2021-06-18 13:20:54 +02:00
|
|
|
|
<div id="fmicon" on:click={toggleFold} class="fmCollapse">Frontmatter</div>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
<span id="frontmatter" class="fmHidden">
|
|
|
|
|
{#each Object.entries(frontmatter) as fmItems}
|
2021-06-04 01:38:27 +02:00
|
|
|
|
{#each fmItems[1] as fmItem, i}
|
2021-08-22 00:34:00 +02:00
|
|
|
|
{#if ["ascription", "triad"].includes(fmItems[0])}
|
|
|
|
|
<div class="fmMeta">
|
|
|
|
|
<div class="fmMetaTitle">
|
|
|
|
|
{fmItems[0]}<button
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => removeTier(fmItems[0], fmItem)}
|
|
|
|
|
on:mouseover={fmItemDottedBorder}
|
|
|
|
|
on:mouseout={fmItemNoBorder}>×</button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fmItem">
|
|
|
|
|
<SpKeys
|
|
|
|
|
index={i}
|
|
|
|
|
fmKeyType={fmItems[0]}
|
|
|
|
|
{fmItem}
|
|
|
|
|
{hases}
|
|
|
|
|
{hasesCandidates}
|
|
|
|
|
on:hasTiersSelected={newTier}
|
|
|
|
|
/>
|
|
|
|
|
<SpTiers
|
|
|
|
|
on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers}
|
|
|
|
|
index={i}
|
|
|
|
|
fmKeyType={fmItems[0]}
|
|
|
|
|
{fmItem}
|
|
|
|
|
/>
|
|
|
|
|
<SpCandidates
|
|
|
|
|
on:addToTiersRemoveFromCandidates={addToTiersRemoveFromCandidates}
|
|
|
|
|
index={i}
|
|
|
|
|
fmKeyType={fmItems[0]}
|
|
|
|
|
{fmItem}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
{:else if fmItems[0] == "journal"}
|
2021-08-22 00:34:00 +02:00
|
|
|
|
<div class="fmMeta">
|
|
|
|
|
<div class="fmMetaTitle">
|
|
|
|
|
{fmItems[0]}<button
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => removeTier(fmItems[0], fmItem)}
|
|
|
|
|
on:mouseover={fmItemDottedBorder}
|
|
|
|
|
on:mouseout={fmItemNoBorder}>×</button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fmItem">
|
|
|
|
|
<SpJournal {fmItem} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
{/if}
|
2021-06-02 02:02:20 +02:00
|
|
|
|
{/each}
|
2021-06-08 12:39:07 +02:00
|
|
|
|
{/each}
|
2021-08-18 15:00:45 +02:00
|
|
|
|
<div class="buttons news">
|
2021-08-22 00:34:00 +02:00
|
|
|
|
<div id="newtriad" class="newtiers button" on:click={() => newTier("triad", "_new", null)}>
|
|
|
|
|
NEW TIER
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
id="newascription"
|
|
|
|
|
class="newtiers button"
|
|
|
|
|
on:click={() => newTier("ascription", "_new", null)}
|
|
|
|
|
>
|
2021-08-18 15:00:45 +02:00
|
|
|
|
NEW ASCRIPTION
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
</span>
|
|
|
|
|
<div class="formgrid">
|
2021-06-18 13:20:54 +02:00
|
|
|
|
<label for="pagecontent">Content:</label>
|
2021-06-08 12:39:07 +02:00
|
|
|
|
<textarea
|
2021-06-18 13:20:54 +02:00
|
|
|
|
id="pagecontent"
|
2021-06-08 12:39:07 +02:00
|
|
|
|
bind:value={v}
|
|
|
|
|
oninput="this.style.height = '';this.style.height = this.scrollHeight + 3 + 'px'"
|
|
|
|
|
/>
|
|
|
|
|
{#if document.location.protocol.substring(0, 4) != "file"}
|
|
|
|
|
<label for="publish">Publish</label>
|
|
|
|
|
<input type="checkbox" id="publish" name="publish" />
|
2021-06-02 02:02:20 +02:00
|
|
|
|
{/if}
|
2021-06-08 12:39:07 +02:00
|
|
|
|
<label for="offline">Offline</label>
|
|
|
|
|
<input type="checkbox" id="offline" name="offline" />
|
|
|
|
|
<input type="hidden" name="relpermalink" bind:value={relpermalink} />
|
|
|
|
|
<input type="hidden" name="relpath" bind:value={relpath} />
|
|
|
|
|
<input type="hidden" name="protocol" bind:value={protocol} />
|
|
|
|
|
<button id="sandpointsButton">COMMIT/SAVE</button>
|
|
|
|
|
</div>
|
2021-03-25 16:02:55 +01:00
|
|
|
|
</form>
|
|
|
|
|
</main>
|