Compare commits
No commits in common. '85eeb3e5c031433c5e6900f5de1b863fff57049e' and '1823db0bc3dbc97e6dd26a0f627029d9cd72dc3f' have entirely different histories.
85eeb3e5c0
...
1823db0bc3
File diff suppressed because one or more lines are too long
@ -1,22 +0,0 @@
|
||||
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,107 +1,133 @@
|
||||
import json
|
||||
import frontmatter
|
||||
import os
|
||||
from . import crossword
|
||||
import string
|
||||
|
||||
def dump(order=None):
|
||||
|
||||
# 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']
|
||||
def dump(order=None):
|
||||
# list all the folders
|
||||
path = "postit/static/contents"
|
||||
|
||||
folders = order
|
||||
path = "postit/static/contents"
|
||||
|
||||
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()]
|
||||
|
||||
# Total number of postit
|
||||
total = 0
|
||||
|
||||
# Dictionary to fill with the contributions
|
||||
contents = {}
|
||||
|
||||
|
||||
total = 0
|
||||
|
||||
for folder in folders:
|
||||
# Initialize the contribution as an empty list of postit
|
||||
contribution = []
|
||||
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:
|
||||
metadata, body = frontmatter.parse(f.read())
|
||||
|
||||
for content in metadata["contents"]:
|
||||
if type(content) == dict:
|
||||
|
||||
# For each entry in the contents list create a default postit dictionary
|
||||
# with the title of the contribution
|
||||
if "img" in content:
|
||||
postit = {
|
||||
'title' : metadata['title']
|
||||
"title": metadata["title"],
|
||||
"description": content["alt"],
|
||||
"img": content["img"],
|
||||
"slug": folder,
|
||||
}
|
||||
|
||||
# We have basically 2 types of postit:
|
||||
# 1. Simple postit with just a string of text
|
||||
# 2. Complex postit with different informations
|
||||
|
||||
# ii) We start from this second kind, that is loaded as a dictionary
|
||||
if type(content) == dict:
|
||||
# this is temporary, sorry
|
||||
elif "type" in content:
|
||||
if content["type"] == 'mimic-colophon':
|
||||
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,
|
||||
}
|
||||
|
||||
# Pass all the properties from the yaml object to the post-it dictionary
|
||||
for key in content:
|
||||
postit[key] = content[key]
|
||||
elif "card" in content:
|
||||
postit = {
|
||||
"title": metadata["title"],
|
||||
"card": content["card"],
|
||||
"quote": content["quote"],
|
||||
"motivation": content["motivation"],
|
||||
"vision": content["vision"],
|
||||
"empathy": content["empathy"],
|
||||
"positivity": content["positivity"],
|
||||
"slug": folder,
|
||||
}
|
||||
|
||||
# --------------------------
|
||||
# Custom post-it generation
|
||||
# Add here the function for generate dynamic postit
|
||||
# (such as the crossword imaginary grid)
|
||||
elif any(position in ['nw','ne','sw','se'] for position in content):
|
||||
postit = {
|
||||
"title": metadata["title"],
|
||||
"slug": folder,
|
||||
}
|
||||
for position in content:
|
||||
postit[position] = content[position]
|
||||
|
||||
# Generate the Imaginary Grid for the Crossword game
|
||||
# (Only for the Loot Box category)
|
||||
if "word" in content and content['category'] != 'Loot Box':
|
||||
elif "word" in content and content['category'] != 'Loot Box':
|
||||
continue
|
||||
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"]:
|
||||
# Generate a postit for each letter in the word
|
||||
for cell in crossword.generate_grid(content['word'], content["start"], content["direction"]):
|
||||
start = (
|
||||
string.ascii_uppercase.index(content["start"][0]),
|
||||
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(
|
||||
{
|
||||
"title": metadata["title"],
|
||||
"definition": " ",
|
||||
"category": content["category"],
|
||||
"start": cell,
|
||||
})
|
||||
|
||||
|
||||
#----------------------------
|
||||
"start": start_f,
|
||||
"word": content["word"],
|
||||
"direction": content["direction"],
|
||||
"slug": folder,
|
||||
}
|
||||
)
|
||||
|
||||
else:
|
||||
# i) Simple string postit
|
||||
postit["description"] = content
|
||||
|
||||
# Add the postit to the contribution
|
||||
postit = {
|
||||
"title": metadata["title"],
|
||||
"description": content,
|
||||
"slug": folder,
|
||||
}
|
||||
contribution.append(postit)
|
||||
|
||||
# Log the amount of postit for the current contribution
|
||||
amount = len(contribution)
|
||||
print(f"{amount:03} - {folder}")
|
||||
|
||||
# Add the contribution to the total amount
|
||||
total = total + amount
|
||||
|
||||
# Add the contribution to the contents object
|
||||
contents[folder] = contribution
|
||||
|
||||
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(e)
|
||||
|
||||
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:
|
||||
f.write(json.dumps(contents))
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 08d68b497fb2fa47d7d9f74c86600a0b01b7566b
|
||||
Subproject commit 1691c432b0126c3adc4c292e66c6efd9032f14f5
|
@ -1,22 +0,0 @@
|
||||
: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;
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// 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);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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