Compare commits
3 Commits
1823db0bc3
...
85eeb3e5c0
Author | SHA1 | Date |
---|---|---|
km0 | 85eeb3e5c0 | 3 years ago |
km0 | 3233949d44 | 3 years ago |
km0 | a895aad1ed | 3 years ago |
File diff suppressed because one or more lines are too long
@ -0,0 +1,22 @@
|
|||||||
|
from string import ascii_uppercase
|
||||||
|
|
||||||
|
def generate_grid(word, origin, direction):
|
||||||
|
|
||||||
|
start = (
|
||||||
|
ascii_uppercase.index(origin[0]),
|
||||||
|
int(origin[1:]),
|
||||||
|
)
|
||||||
|
|
||||||
|
cells = []
|
||||||
|
for i in range(len(word)):
|
||||||
|
if direction == "H":
|
||||||
|
# increase number
|
||||||
|
start_f = f"{ascii_uppercase[start[0]]}{start[1] + i}"
|
||||||
|
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# increase letter
|
||||||
|
start_f = f"{ascii_uppercase[start[0] + i]}{start[1]}"
|
||||||
|
pass
|
||||||
|
cells.append(start_f)
|
||||||
|
return cells
|
@ -1,133 +1,107 @@
|
|||||||
import json
|
import json
|
||||||
import frontmatter
|
import frontmatter
|
||||||
import os
|
import os
|
||||||
import string
|
from . import crossword
|
||||||
|
|
||||||
|
|
||||||
def dump(order=None):
|
def dump(order=None):
|
||||||
# list all the folders
|
|
||||||
path = "postit/static/contents"
|
# The function can receive an optional order for the contents
|
||||||
|
# in the form of a list of folder like
|
||||||
|
# ['intro','what-is-a-loot-box', 'crosswords', 'one-sentence-game-ideas', 'nim', 'mimic', 'unfinished-thoughts', 'the-leader', 'connect-less', 'xquisite', 'katamari', 'life-hacks', 'karaoke', 'outro']
|
||||||
|
|
||||||
folders = order
|
folders = order
|
||||||
|
path = "postit/static/contents"
|
||||||
|
|
||||||
if folders == None:
|
if folders == None:
|
||||||
|
# If no order is passed, list all the folders in the contents directory
|
||||||
folders = [f.name for f in os.scandir(path) if f.is_dir()]
|
folders = [f.name for f in os.scandir(path) if f.is_dir()]
|
||||||
|
|
||||||
contents = {}
|
# Total number of postit
|
||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
|
# Dictionary to fill with the contributions
|
||||||
|
contents = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
|
# Initialize the contribution as an empty list of postit
|
||||||
contribution = []
|
contribution = []
|
||||||
try:
|
try:
|
||||||
|
# Load the file from a contents.md file
|
||||||
|
# (we are intrested only in the yaml metadata tho)
|
||||||
with open(f"{path}/{folder}/contents.md", "r", encoding="utf8") as f:
|
with open(f"{path}/{folder}/contents.md", "r", encoding="utf8") as f:
|
||||||
metadata, body = frontmatter.parse(f.read())
|
metadata, body = frontmatter.parse(f.read())
|
||||||
|
|
||||||
for content in metadata["contents"]:
|
for content in metadata["contents"]:
|
||||||
if type(content) == dict:
|
|
||||||
|
|
||||||
if "img" in content:
|
# For each entry in the contents list create a default postit dictionary
|
||||||
|
# with the title of the contribution
|
||||||
postit = {
|
postit = {
|
||||||
"title": metadata["title"],
|
'title' : metadata['title']
|
||||||
"description": content["alt"],
|
|
||||||
"img": content["img"],
|
|
||||||
"slug": folder,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# this is temporary, sorry
|
# We have basically 2 types of postit:
|
||||||
elif "type" in content:
|
# 1. Simple postit with just a string of text
|
||||||
if content["type"] == 'mimic-colophon':
|
# 2. Complex postit with different informations
|
||||||
postit = {
|
|
||||||
"title": metadata['title'],
|
|
||||||
"type": content['type'],
|
|
||||||
"original": content['original'],
|
|
||||||
"original-credits": content['original-credits'],
|
|
||||||
"original-action": content['original-action'],
|
|
||||||
"original-date": content['original-date'],
|
|
||||||
"current": content['current'],
|
|
||||||
'current-credits': content['current-credits'],
|
|
||||||
"current-action": content['current-action'],
|
|
||||||
"current-date": content['current-date'],
|
|
||||||
"slug": folder,
|
|
||||||
}
|
|
||||||
|
|
||||||
elif "card" in content:
|
# ii) We start from this second kind, that is loaded as a dictionary
|
||||||
postit = {
|
if type(content) == dict:
|
||||||
"title": metadata["title"],
|
|
||||||
"card": content["card"],
|
|
||||||
"quote": content["quote"],
|
|
||||||
"motivation": content["motivation"],
|
|
||||||
"vision": content["vision"],
|
|
||||||
"empathy": content["empathy"],
|
|
||||||
"positivity": content["positivity"],
|
|
||||||
"slug": folder,
|
|
||||||
}
|
|
||||||
|
|
||||||
elif any(position in ['nw','ne','sw','se'] for position in content):
|
# Pass all the properties from the yaml object to the post-it dictionary
|
||||||
postit = {
|
for key in content:
|
||||||
"title": metadata["title"],
|
postit[key] = content[key]
|
||||||
"slug": folder,
|
|
||||||
}
|
# --------------------------
|
||||||
for position in content:
|
# Custom post-it generation
|
||||||
postit[position] = content[position]
|
# Add here the function for generate dynamic postit
|
||||||
|
# (such as the crossword imaginary grid)
|
||||||
|
|
||||||
elif "word" in content and content['category'] != 'Loot Box':
|
# Generate the Imaginary Grid for the Crossword game
|
||||||
|
# (Only for the Loot Box category)
|
||||||
|
if "word" in content and content['category'] != 'Loot Box':
|
||||||
continue
|
continue
|
||||||
elif "word" in content:
|
elif "word" in content:
|
||||||
postit = {
|
|
||||||
"title": metadata["title"],
|
|
||||||
"definition": content["definition"],
|
|
||||||
"category": content["category"],
|
|
||||||
"start": content["start"],
|
|
||||||
"word": content["word"],
|
|
||||||
"direction": content["direction"],
|
|
||||||
"slug": folder,
|
|
||||||
}
|
|
||||||
if content["word"]:
|
if content["word"]:
|
||||||
start = (
|
# Generate a postit for each letter in the word
|
||||||
string.ascii_uppercase.index(content["start"][0]),
|
for cell in crossword.generate_grid(content['word'], content["start"], content["direction"]):
|
||||||
int(content["start"][1:]),
|
|
||||||
)
|
|
||||||
# print(start)
|
|
||||||
for i in range(len(content["word"])):
|
|
||||||
if content["direction"] == "H":
|
|
||||||
# increase number
|
|
||||||
start_f = f"{string.ascii_uppercase[start[0]]}{start[1] + i}"
|
|
||||||
# print(start_f)
|
|
||||||
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
# increase letter
|
|
||||||
start_f = f"{string.ascii_uppercase[start[0] + i]}{start[1]}"
|
|
||||||
# print(start_f)
|
|
||||||
pass
|
|
||||||
contribution.append(
|
contribution.append(
|
||||||
{
|
{
|
||||||
"title": metadata["title"],
|
"title": metadata["title"],
|
||||||
"definition": " ",
|
"definition": " ",
|
||||||
"category": content["category"],
|
"category": content["category"],
|
||||||
"start": start_f,
|
"start": cell,
|
||||||
"word": content["word"],
|
})
|
||||||
"direction": content["direction"],
|
|
||||||
"slug": folder,
|
|
||||||
}
|
#----------------------------
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
postit = {
|
# i) Simple string postit
|
||||||
"title": metadata["title"],
|
postit["description"] = content
|
||||||
"description": content,
|
|
||||||
"slug": folder,
|
# Add the postit to the contribution
|
||||||
}
|
|
||||||
contribution.append(postit)
|
contribution.append(postit)
|
||||||
|
|
||||||
|
# Log the amount of postit for the current contribution
|
||||||
amount = len(contribution)
|
amount = len(contribution)
|
||||||
print(f"{amount:03} - {folder}")
|
print(f"{amount:03} - {folder}")
|
||||||
|
|
||||||
|
# Add the contribution to the total amount
|
||||||
total = total + amount
|
total = total + amount
|
||||||
|
|
||||||
|
# Add the contribution to the contents object
|
||||||
contents[folder] = contribution
|
contents[folder] = contribution
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# If a markdown file is broken print the error and move on
|
||||||
|
# without breaking everything
|
||||||
print(f"{folder} has an error!")
|
print(f"{folder} has an error!")
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
print(f'Total: {total}')
|
print(f'Total: {total}')
|
||||||
|
|
||||||
|
# Store the postit in a JSON file
|
||||||
|
# in order to avoid repeating this process everytime we want the postit.
|
||||||
with open("postit/contents.json", "w") as f:
|
with open("postit/contents.json", "w") as f:
|
||||||
f.write(json.dumps(contents))
|
f.write(json.dumps(contents))
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 1691c432b0126c3adc4c292e66c6efd9032f14f5
|
Subproject commit 08d68b497fb2fa47d7d9f74c86600a0b01b7566b
|
@ -0,0 +1,22 @@
|
|||||||
|
:root {
|
||||||
|
--color: var(--purple);
|
||||||
|
--background: var(--purple-bg);
|
||||||
|
|
||||||
|
--alt: var(--orange);
|
||||||
|
--alt-bg: var(--orange-bg);
|
||||||
|
|
||||||
|
--orange: #ff5416;
|
||||||
|
--orange-bg: #ffb58d;
|
||||||
|
--purple: #7d50ff;
|
||||||
|
--purple-bg: #cec6ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--color);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
body {
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: var(--color);
|
||||||
|
padding: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: currentColor;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-weight: normal;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button#color {
|
||||||
|
position: absolute;
|
||||||
|
right: 32px;
|
||||||
|
top: 52px;
|
||||||
|
display: inline-block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
border-radius: 0;
|
||||||
|
border: none;
|
||||||
|
background-color: var(--alt-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
button#color:hover {
|
||||||
|
transition: transform 0.1s ease-out;
|
||||||
|
transform: scale(1.05);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
// I really don't like this code but it's ok for now...
|
||||||
|
|
||||||
|
let main = true;
|
||||||
|
|
||||||
|
// Set a reference in the localStorage with the main color
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
color = getCookie("color");
|
||||||
|
|
||||||
|
if (color == "purple" || color == "") {
|
||||||
|
document.documentElement.style.setProperty("--color", "var(--purple)");
|
||||||
|
document.documentElement.style.setProperty("--background", "var(--purple-bg)");
|
||||||
|
document.documentElement.style.setProperty("--alt", "var(--orange)");
|
||||||
|
document.documentElement.style.setProperty("--alt-bg", "var(--orange-bg)");
|
||||||
|
setCookie("color", "purple", 7);
|
||||||
|
main = true;
|
||||||
|
} else {
|
||||||
|
document.documentElement.style.setProperty("--color", "var(--orange)");
|
||||||
|
document.documentElement.style.setProperty("--background", "var(--orange-bg)");
|
||||||
|
document.documentElement.style.setProperty("--alt", "var(--purple)");
|
||||||
|
document.documentElement.style.setProperty("--alt-bg", "var(--purple-bg)");
|
||||||
|
setCookie("color", "orange", 7);
|
||||||
|
main = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toggle color button
|
||||||
|
const colorButton = document.getElementById("color");
|
||||||
|
colorButton.addEventListener("click", () => {
|
||||||
|
toggleColor();
|
||||||
|
});
|
||||||
|
|
||||||
|
function toggleColor() {
|
||||||
|
var style = getComputedStyle(document.body);
|
||||||
|
|
||||||
|
// get the current palette
|
||||||
|
currentColor = style.getPropertyValue("--color");
|
||||||
|
currentBg = style.getPropertyValue("--background");
|
||||||
|
altColor = style.getPropertyValue("--alt");
|
||||||
|
altBg = style.getPropertyValue("--alt-bg");
|
||||||
|
|
||||||
|
// and swap the order
|
||||||
|
document.documentElement.style.setProperty("--color", altColor);
|
||||||
|
document.documentElement.style.setProperty("--background", altBg);
|
||||||
|
document.documentElement.style.setProperty("--alt", currentColor);
|
||||||
|
document.documentElement.style.setProperty("--alt-bg", currentBg);
|
||||||
|
|
||||||
|
// set a reference in a cookie to share it with the generator page
|
||||||
|
main = !main;
|
||||||
|
setCookie("color", main ? "purple" : "orange", 7);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
function setCookie(name, value, days) {
|
||||||
|
var expires = "";
|
||||||
|
if (days) {
|
||||||
|
var date = new Date();
|
||||||
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||||
|
expires = "; expires=" + date.toUTCString();
|
||||||
|
}
|
||||||
|
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||||
|
}
|
||||||
|
function getCookie(name) {
|
||||||
|
var nameEQ = name + "=";
|
||||||
|
var ca = document.cookie.split(";");
|
||||||
|
for (var i = 0; i < ca.length; i++) {
|
||||||
|
var c = ca[i];
|
||||||
|
while (c.charAt(0) == " ") c = c.substring(1, c.length);
|
||||||
|
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function eraseCookie(name) {
|
||||||
|
document.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
|
||||||
|
}
|
Loading…
Reference in New Issue