Compare commits
4 commits
2753be8450
...
f5af0012f0
Author | SHA1 | Date | |
---|---|---|---|
f5af0012f0 | |||
5c16681285 | |||
a1d2c00a03 | |||
847a228f5a |
3 changed files with 125 additions and 65 deletions
|
@ -50,6 +50,15 @@ button:disabled {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
color: #333;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
border: 1px solid lightgrey;
|
||||||
|
padding: 0.2em 0.4em;
|
||||||
|
grid-column: 2/3;
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
button:not(:disabled):active {
|
button:not(:disabled):active {
|
||||||
background-color: #ddd;
|
background-color: #ddd;
|
||||||
}
|
}
|
||||||
|
@ -177,3 +186,11 @@ select {
|
||||||
#fmicon, #frontmatter, input.hasinput {
|
#fmicon, #frontmatter, input.hasinput {
|
||||||
background-color: #ffccbc;
|
background-color: #ffccbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#newtier {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.news {
|
||||||
|
grid-column: 2/3;
|
||||||
|
}
|
||||||
|
|
171
src/App.svelte
171
src/App.svelte
|
@ -10,11 +10,10 @@
|
||||||
let relpermalink = "";
|
let relpermalink = "";
|
||||||
let protocol = "";
|
let protocol = "";
|
||||||
let title = "Foo bar";
|
let title = "Foo bar";
|
||||||
let hases = [];
|
let hases = [];
|
||||||
let hasesCandidates = [];
|
let hasesCandidates = [];
|
||||||
let frontmatter = {};
|
let frontmatter = {};
|
||||||
let frontmatterLoaded = false;
|
frontmatter["triad"] = [];
|
||||||
frontmatter["triad"] = [];
|
|
||||||
frontmatter["ascriptions"] = [];
|
frontmatter["ascriptions"] = [];
|
||||||
frontmatter["notsand"] = [];
|
frontmatter["notsand"] = [];
|
||||||
|
|
||||||
|
@ -32,19 +31,61 @@
|
||||||
return Array.from(diff);
|
return Array.from(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newTier(fmKeyType, fmKey, fmValue = "") {
|
||||||
|
console.log("newTier", fmKeyType, fmKey);
|
||||||
|
|
||||||
|
if (fmKeyType == "ascriptions" && fmKey == "_new") {
|
||||||
|
hasesCandidates = [... new Set(reckonHasesCandidates())]
|
||||||
|
if (hasesCandidates.length > 0) {
|
||||||
|
fmKey = hasesCandidates[0]
|
||||||
|
console.log(hasesCandidates, fmKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let tiers = [];
|
||||||
|
let candidates = [];
|
||||||
|
METASP[fmKey].tiers.forEach((t) => {
|
||||||
|
if (fmValue.includes(t.file)) {
|
||||||
|
tiers.push(t);
|
||||||
|
} else {
|
||||||
|
candidates.push(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frontmatter[fmKeyType].push({
|
||||||
|
fmKey: fmKey,
|
||||||
|
tiers: tiers,
|
||||||
|
candidates: [...new Set(candidates)],
|
||||||
|
});
|
||||||
|
frontmatter = { ...frontmatter };
|
||||||
|
}
|
||||||
|
|
||||||
function newHasTiers(arrgs) {
|
function newHasTiers(arrgs) {
|
||||||
let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail;
|
let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail;
|
||||||
|
hasesCandidates = [... new Set(reckonHasesCandidates())]
|
||||||
|
console.log(hasesCandidates)
|
||||||
|
if (fmKeyType=="triad" && oldFmKey == "_new") {
|
||||||
|
if (hasesCandidates.length > 0) {
|
||||||
|
newFmKey = hasesCandidates[0];
|
||||||
|
if (hasesCandidates.length > 1) {
|
||||||
|
oldFmKey = hasesCandidates[1]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
frontmatter[fmKeyType][index] = {
|
frontmatter[fmKeyType][index] = {
|
||||||
fmKey: newFmKey,
|
fmKey: newFmKey,
|
||||||
tiers: [],
|
tiers: [],
|
||||||
candidates: METASP[newFmKey].tiers,
|
candidates: METASP[newFmKey].tiers,
|
||||||
};
|
};
|
||||||
|
|
||||||
hasesCandidates = hasesCandidates.filter((h) => h != newFmKey);
|
hasesCandidates = hasesCandidates.filter((h) => h != newFmKey);
|
||||||
hasesCandidates = [...hasesCandidates, oldFmKey];
|
hasesCandidates = [...hasesCandidates, oldFmKey];
|
||||||
|
toggleNewTriadButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadHugoPageMetadata(editHash) {
|
function loadHugoPageMetadata(editHash) {
|
||||||
var el = document.createElement("script");
|
let el = document.createElement("script");
|
||||||
el.onload = () => {
|
el.onload = () => {
|
||||||
v = repo.content;
|
v = repo.content;
|
||||||
if (v.startsWith("\n")) {
|
if (v.startsWith("\n")) {
|
||||||
|
@ -54,8 +95,8 @@
|
||||||
relpath = repo.path;
|
relpath = repo.path;
|
||||||
relpermalink = repo.relpermalink;
|
relpermalink = repo.relpermalink;
|
||||||
protocol = document.location.protocol.substring(0, 4);
|
protocol = document.location.protocol.substring(0, 4);
|
||||||
let notSelf = Object.entries(METASP).filter(n => n[1].singular == relpath.split("/")[0])[0][0]
|
const notSelf = Object.entries(METASP).filter((n) => n[1].singular == relpath.split("/")[0])[0][0];
|
||||||
hases = Object.keys(METASP).filter(k => k != notSelf);
|
hases = Object.keys(METASP).filter((k) => k != notSelf);
|
||||||
Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => {
|
Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => {
|
||||||
let fmKeyType = "";
|
let fmKeyType = "";
|
||||||
if (fmKey.toLowerCase().startsWith("has_")) {
|
if (fmKey.toLowerCase().startsWith("has_")) {
|
||||||
|
@ -73,20 +114,7 @@
|
||||||
|
|
||||||
if (["triad", "ascriptions"].includes(fmKeyType)) {
|
if (["triad", "ascriptions"].includes(fmKeyType)) {
|
||||||
if (Array.isArray(fmValue)) {
|
if (Array.isArray(fmValue)) {
|
||||||
let tiers = [];
|
newTier(fmKeyType, fmKey, fmValue);
|
||||||
let candidates = [];
|
|
||||||
METASP[fmKey].tiers.forEach((t) => {
|
|
||||||
if (fmValue.includes(t.file)) {
|
|
||||||
tiers.push(t);
|
|
||||||
} else {
|
|
||||||
candidates.push(t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
frontmatter[fmKeyType].push({
|
|
||||||
fmKey: fmKey,
|
|
||||||
tiers: tiers,
|
|
||||||
candidates: candidates,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else if (fmKeyType == "journal") {
|
} else if (fmKeyType == "journal") {
|
||||||
frontmatter["journal"] || (frontmatter["journal"] = []);
|
frontmatter["journal"] || (frontmatter["journal"] = []);
|
||||||
|
@ -99,25 +127,28 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hasesCandidates = diffArrr(hases, [
|
hasesCandidates = reckonHasesCandidates();
|
||||||
...frontmatter["triad"].map((t) => {
|
const tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
|
||||||
return t.fmKey;
|
|
||||||
}),
|
|
||||||
...frontmatter["ascriptions"].map((t) => {
|
|
||||||
return t.fmKey;
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
let tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
|
|
||||||
title = repo.frontmatter[tkey];
|
title = repo.frontmatter[tkey];
|
||||||
frontmatterLoaded = true;
|
|
||||||
|
toggleNewTriadButton();
|
||||||
};
|
};
|
||||||
el.src = `../js/repo/${editHash}.js`;
|
el.src = `../js/repo/${editHash}.js`;
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reckonHasesCandidates() {
|
||||||
|
return diffArrr(hases, [
|
||||||
|
...frontmatter["triad"].map((t) => {
|
||||||
|
return t.fmKey;
|
||||||
|
}),
|
||||||
|
...frontmatter["ascriptions"].map((t) => {
|
||||||
|
return t.fmKey;
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
function addToCandidatesRemoveFromTiers(arrgs) {
|
function addToCandidatesRemoveFromTiers(arrgs) {
|
||||||
let [fmKeyType, index, fmKey, tier] = arrgs.detail;
|
const [fmKeyType, index, fmKey, tier] = arrgs.detail;
|
||||||
frontmatter[fmKeyType][index]["fmKey"] = fmKey;
|
frontmatter[fmKeyType][index]["fmKey"] = fmKey;
|
||||||
frontmatter[fmKeyType][index]["tiers"] = frontmatter[fmKeyType][index]["tiers"].filter(
|
frontmatter[fmKeyType][index]["tiers"] = frontmatter[fmKeyType][index]["tiers"].filter(
|
||||||
(t) => t !== tier
|
(t) => t !== tier
|
||||||
|
@ -126,7 +157,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToTiersRemoveFromCandidates(arrgs) {
|
function addToTiersRemoveFromCandidates(arrgs) {
|
||||||
let [fmKeyType, index, , value] = arrgs.detail;
|
const [fmKeyType, index, , value] = arrgs.detail;
|
||||||
const tier = frontmatter[fmKeyType][index]["candidates"].filter((t) => t.file == value);
|
const tier = frontmatter[fmKeyType][index]["candidates"].filter((t) => t.file == value);
|
||||||
if (tier.length > 0) {
|
if (tier.length > 0) {
|
||||||
frontmatter[fmKeyType][index]["tiers"] = [...frontmatter[fmKeyType][index]["tiers"], tier[0]];
|
frontmatter[fmKeyType][index]["tiers"] = [...frontmatter[fmKeyType][index]["tiers"], tier[0]];
|
||||||
|
@ -155,37 +186,45 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function newFrontmatter() {
|
function newFrontmatter() {
|
||||||
return Object.entries(frontmatter).filter(val => val[1].length == 0).map(key => key[0])
|
return Object.entries(frontmatter)
|
||||||
}
|
.filter((val) => val[1].length == 0)
|
||||||
|
.map((key) => key[0]);
|
||||||
|
}
|
||||||
|
|
||||||
function checkTriad() {
|
function toggleNewTriadButton() {
|
||||||
let ct = Object.entries(frontmatter).filter(i => i[1].length == 0 && i[0] == "triad")
|
const ct = Object.entries(frontmatter).filter((i) => i[1].length == 0 && i[0] == "triad");
|
||||||
return ct.length == 0 ? false : true
|
if (document.getElementById("newtier")) {
|
||||||
}
|
if (ct.length == 0) {
|
||||||
|
document.getElementById("newtier").style.display = "none";
|
||||||
|
} else {
|
||||||
|
document.getElementById("newtier").style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function newTriad() {
|
function newTriad() {
|
||||||
newHasTiers({"detail": ["triad", 0, "authors", "editors"]})
|
newHasTiers({ detail: ["triad", 0, "_new", ""] });
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatchHash() {
|
function dispatchHash() {
|
||||||
var searchParams = new URLSearchParams(location.search);
|
const searchParams = new URLSearchParams(location.search);
|
||||||
let editHash = searchParams.get('edit')
|
const editHash = searchParams.get("edit");
|
||||||
if (editHash) {
|
if (editHash) {
|
||||||
loadHugoPageMetadata(editHash)
|
loadHugoPageMetadata(editHash);
|
||||||
} else {
|
} else {
|
||||||
let newPage = searchParams.get('new')
|
let newPage = searchParams.get("new");
|
||||||
console.log(newPage)
|
console.log(newPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
dispatchHash();
|
dispatchHash();
|
||||||
// loadHugoPageMetadata();
|
// loadHugoPageMetadata();
|
||||||
console.dir(frontmatter);
|
console.dir(frontmatter);
|
||||||
});
|
});
|
||||||
|
|
||||||
$: hashChanged = ()=> dispatchHash();
|
$: hashChanged = () => dispatchHash();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window on:keyup={keyUp} on:hashchange={hashChanged} />
|
<svelte:window on:keyup={keyUp} on:hashchange={hashChanged} />
|
||||||
|
@ -206,6 +245,7 @@
|
||||||
{hases}
|
{hases}
|
||||||
{hasesCandidates}
|
{hasesCandidates}
|
||||||
on:hasTiersSelected={newHasTiers}
|
on:hasTiersSelected={newHasTiers}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
<SpTiers
|
<SpTiers
|
||||||
on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers}
|
on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers}
|
||||||
|
@ -224,9 +264,12 @@
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
{/each}
|
||||||
{#if frontmatterLoaded && checkTriad()}
|
<div class="buttons news">
|
||||||
<div on:click="{newTriad}">NEW TRIAD TIER</div>
|
<div id="newtier" class="button" on:click={newTriad}>NEW TIER</div>
|
||||||
{/if}
|
<div id="newascription" class="button" on:click={() => newTier("ascriptions", "_new")}>
|
||||||
|
NEW ASCRIPTION
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<div class="formgrid">
|
<div class="formgrid">
|
||||||
<label for="pagecontent">Content:</label>
|
<label for="pagecontent">Content:</label>
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
on:click={swapTier(tier, -1)}
|
on:click={swapTier(tier, -1)}
|
||||||
disabled={i == 0 ? true : false}>⇑</button
|
disabled={i == 0 ? true : false}>⇑</button
|
||||||
>
|
>
|
||||||
<button type="button" on:click={removeTier(tier)}>×</button>
|
<button type="button" on:click={()=> removeTier(tier)}>×</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
Loading…
Add table
Reference in a new issue