2021-03-25 16:02:55 +01:00
|
|
|
<script>
|
2021-04-24 01:14:16 +02:00
|
|
|
import SpTitle from './SpTitle.svelte'
|
|
|
|
import SpHasTiers from './SpHasTiers.svelte'
|
2021-04-28 17:09:45 +02:00
|
|
|
import SpHasWhat from './SpHasWhat.svelte'
|
2021-04-24 01:14:16 +02:00
|
|
|
import SpHasCandidates from './SpHasCandidates.svelte'
|
2021-03-25 16:02:55 +01:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
let v = "loading...";
|
2021-04-24 01:14:16 +02:00
|
|
|
let relpath = "";
|
|
|
|
let relpermalink = "";
|
|
|
|
let protocol = "";
|
|
|
|
let title = "Foo bar";
|
2021-06-02 02:02:20 +02:00
|
|
|
|
2021-04-28 17:09:45 +02:00
|
|
|
let hases = [];
|
2021-06-04 01:38:27 +02:00
|
|
|
let hasesCandidates = [];
|
2021-06-02 02:02:20 +02:00
|
|
|
let frontmatter = {}
|
2021-06-04 01:38:27 +02:00
|
|
|
frontmatter['triad'] = [];
|
|
|
|
frontmatter['ascriptions'] = [];
|
2021-06-02 02:02:20 +02:00
|
|
|
|
2021-04-24 01:14:16 +02:00
|
|
|
function keyUp(e) {
|
|
|
|
if (e.key == "Escape") {
|
|
|
|
window.history.back()
|
2021-04-14 02:14:39 +02:00
|
|
|
}
|
2021-04-13 01:46:33 +02:00
|
|
|
}
|
2021-06-04 01:38:27 +02:00
|
|
|
|
|
|
|
function diffArrr(arr, arrr) {
|
2021-04-24 01:14:16 +02:00
|
|
|
let diff = new Set(arr)
|
|
|
|
for (let e of arrr) {
|
|
|
|
diff.delete(e)
|
|
|
|
}
|
|
|
|
return Array.from(diff)
|
2021-03-25 16:02:55 +01:00
|
|
|
}
|
2021-04-28 17:09:45 +02:00
|
|
|
|
2021-06-02 02:02:20 +02:00
|
|
|
function newHasTiers(arrgs) {
|
2021-06-04 01:38:27 +02:00
|
|
|
let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail;
|
|
|
|
frontmatter[fmKeyType][index] = {'fmKey': newFmKey, 'tiers': [], 'candidates': METASP[newFmKey].tiers}
|
|
|
|
hasesCandidates = [...hasesCandidates, oldFmKey];
|
|
|
|
hasesCandidates = hasesCandidates.filter(h => h != newFmKey);
|
2021-04-28 17:09:45 +02:00
|
|
|
}
|
2021-06-02 02:02:20 +02:00
|
|
|
|
2021-04-24 01:54:25 +02:00
|
|
|
function loadHugoPageMetadata() {
|
2021-03-25 16:02:55 +01:00
|
|
|
var el = document.createElement('script');
|
|
|
|
el.onload = ()=> {
|
|
|
|
v = repo.content;
|
2021-03-27 17:02:33 +01:00
|
|
|
if (v.startsWith("\n")) {
|
|
|
|
v = v.substring(1)
|
|
|
|
}
|
2021-04-24 01:14:16 +02:00
|
|
|
|
|
|
|
relpath = repo.path;
|
|
|
|
relpermalink = repo.relpermalink
|
|
|
|
protocol = document.location.protocol.substring(0,4)
|
2021-04-28 17:09:45 +02:00
|
|
|
hases = Object.keys(METASP)
|
2021-06-02 02:02:20 +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())) {
|
|
|
|
fmKeyType = 'ascriptions'
|
2021-06-04 01:38:27 +02:00
|
|
|
} else {
|
|
|
|
fmKeyType = 'notSandpoints'
|
2021-06-02 02:02:20 +02:00
|
|
|
}
|
|
|
|
|
2021-06-04 01:38:27 +02:00
|
|
|
if (['triad', 'ascriptions'].includes(fmKeyType)) {
|
2021-06-02 02:02:20 +02:00
|
|
|
if (Array.isArray(fmValue)) {
|
2021-06-04 01:38:27 +02:00
|
|
|
let tiers = []
|
|
|
|
let candidates = []
|
2021-06-02 02:02:20 +02:00
|
|
|
METASP[fmKey].tiers.forEach(t => {
|
|
|
|
if (fmValue.includes(t.file)) {
|
2021-06-04 01:38:27 +02:00
|
|
|
tiers.push(t)
|
2021-06-02 02:02:20 +02:00
|
|
|
} else {
|
2021-06-04 01:38:27 +02:00
|
|
|
candidates.push(t)
|
2021-06-02 02:02:20 +02:00
|
|
|
}
|
2021-06-04 01:38:27 +02:00
|
|
|
})
|
|
|
|
frontmatter[fmKeyType].push({'fmKey': fmKey, 'tiers': tiers, 'candidates': candidates})
|
2021-06-02 02:02:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2021-06-04 01:38:27 +02:00
|
|
|
hasesCandidates = diffArrr(hases, [...frontmatter['triad'].map(t => { return t.fmKey }), ...frontmatter['ascriptions'].map(t => { return t.fmKey })])
|
2021-06-02 02:02:20 +02:00
|
|
|
|
2021-04-24 01:14:16 +02:00
|
|
|
let tkey = Object.keys(repo.frontmatter).filter(t => t.toLowerCase() == "title")[0]
|
|
|
|
title = repo.frontmatter[tkey]
|
2021-03-25 16:02:55 +01:00
|
|
|
}
|
|
|
|
el.src = `../js/repo/${location.hash.substring(1)}.js`
|
2021-04-24 01:14:16 +02:00
|
|
|
document.body.appendChild(el)
|
2021-03-25 16:02:55 +01:00
|
|
|
}
|
2021-04-24 01:14:16 +02:00
|
|
|
|
2021-06-02 02:02:20 +02:00
|
|
|
function addToCandidatesRemoveFromTiers(arrgs) {
|
2021-06-04 01:38:27 +02:00
|
|
|
let [fmKeyType, index, fmKey, tier] = arrgs.detail;
|
|
|
|
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-04-15 00:55:21 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 02:02:20 +02:00
|
|
|
function addToTiersRemoveFromCandidates(arrgs) {
|
2021-06-04 01:38:27 +02:00
|
|
|
let [fmKeyType, index, fmKey, value] = arrgs.detail;
|
|
|
|
const tier = frontmatter[fmKeyType][index]['candidates'].filter(t => t.file == value)
|
2021-06-02 02:02:20 +02:00
|
|
|
if (tier.length > 0) {
|
2021-06-04 01:38:27 +02:00
|
|
|
frontmatter[fmKeyType][index]['tiers'] = [...frontmatter[fmKeyType][index]['tiers'], tier[0]]
|
|
|
|
frontmatter[fmKeyType][index]['candidates'] = frontmatter[fmKeyType][index]['candidates'].filter(t=> t != tier[0])
|
2021-06-02 02:02:20 +02:00
|
|
|
}
|
2021-04-24 01:14:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-28 17:09:45 +02:00
|
|
|
onMount(()=> {loadHugoPageMetadata()})
|
2021-03-25 16:02:55 +01:00
|
|
|
</script>
|
|
|
|
|
2021-04-24 01:14:16 +02:00
|
|
|
<svelte:window on:keyup={keyUp}/>
|
2021-03-25 16:02:55 +01:00
|
|
|
<main id="sandpoints">
|
|
|
|
<form>
|
2021-04-28 17:35:46 +02:00
|
|
|
<SpTitle relpath={relpath} title={title} />
|
2021-06-02 02:02:20 +02:00
|
|
|
{#each Object.entries(frontmatter) as fmItems}
|
|
|
|
{#if ['ascriptions', 'triad'].includes(fmItems[0])}
|
2021-06-04 01:38:27 +02:00
|
|
|
{#each fmItems[1] as fmItem, i}
|
|
|
|
<SpHasWhat index={i} fmKeyType={fmItems[0]} fmItem={fmItem} hases={hases} hasesCandidates={hasesCandidates} on:hasTiersSelected={newHasTiers} />
|
|
|
|
<SpHasTiers on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers} index={i} fmKeyType={fmItems[0]} fmItem={fmItem} />
|
|
|
|
<SpHasCandidates on:addToTiersRemoveFromCandidates={addToTiersRemoveFromCandidates} index={i} fmKeyType={fmItems[0]} fmItem={fmItem} />
|
2021-06-02 02:02:20 +02:00
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
{/each}
|
2021-04-14 02:14:39 +02:00
|
|
|
<label for="content">Content:</label>
|
|
|
|
<textarea bind:value={v} oninput='this.style.height = "";this.style.height = this.scrollHeight + 3 + "px"'></textarea>
|
2021-03-27 17:02:33 +01:00
|
|
|
{#if document.location.protocol.substring(0,4) != "file"}
|
|
|
|
<label for="publish">Publish</label>
|
|
|
|
<input type="checkbox" id="publish" name="publish" />
|
|
|
|
{/if}
|
2021-03-25 16:02:55 +01:00
|
|
|
<label for="offline">Offline</label>
|
|
|
|
<input type="checkbox" id="offline" name="offline" />
|
2021-04-24 01:14:16 +02:00
|
|
|
<input type="hidden" name="relpermalink" bind:value={relpermalink} />
|
|
|
|
<input type="hidden" name="relpath" bind:value={relpath} />
|
|
|
|
<input type="hidden" name="protocol" bind:value={protocol} />
|
2021-03-27 17:02:33 +01:00
|
|
|
<button id="sandpointsButton">COMMIT/SAVE</button>
|
2021-03-25 16:02:55 +01:00
|
|
|
</form>
|
|
|
|
</main>
|