manetta
3 years ago
commit
ca04c97fff
8 changed files with 62667 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||
|
all: run |
||||
|
|
||||
|
run: |
||||
|
python3 -m http.server |
||||
|
|
||||
|
update: |
||||
|
python3 update.py |
||||
|
|
||||
|
upload: |
||||
|
scp -r Unfolded.html css js fonts varia:public_html/volumetric-regimes/ |
||||
|
|
||||
|
uploadimages: |
||||
|
scp -r images varia:public_html/volumetric-regimes/ |
@ -0,0 +1,180 @@ |
|||||
|
/* CSS for Paged.js interface – v0.2 */ |
||||
|
|
||||
|
/* Change the look */ |
||||
|
:root { |
||||
|
--color-background: whitesmoke; |
||||
|
--color-pageSheet: #cfcfcf; |
||||
|
--color-pageBox: violet; |
||||
|
--color-paper: white; |
||||
|
--color-marginBox: transparent; |
||||
|
--pagedjs-crop-color: black; |
||||
|
--pagedjs-crop-shadow: white; |
||||
|
--pagedjs-crop-stroke: 1px; |
||||
|
} |
||||
|
|
||||
|
/* To define how the book look on the screen: */ |
||||
|
@media screen { |
||||
|
body { |
||||
|
background-color: var(--color-background); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_pages { |
||||
|
display: flex; |
||||
|
width: calc(var(--pagedjs-width) * 2); |
||||
|
flex: 0; |
||||
|
flex-wrap: wrap; |
||||
|
margin: 0 auto; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_page { |
||||
|
background-color: var(--color-paper); |
||||
|
box-shadow: 0 0 0 1px var(--color-pageSheet); |
||||
|
margin: 0; |
||||
|
flex-shrink: 0; |
||||
|
flex-grow: 0; |
||||
|
margin-top: 10mm; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_first_page { |
||||
|
margin-left: var(--pagedjs-width); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_page:last-of-type { |
||||
|
margin-bottom: 10mm; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_pagebox{ |
||||
|
box-shadow: 0 0 0 1px var(--color-pageBox); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page{ |
||||
|
z-index: 20; |
||||
|
width: calc(var(--pagedjs-bleed-left) + var(--pagedjs-pagebox-width))!important; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-crop { |
||||
|
border-color: transparent; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-middle{ |
||||
|
width: 0; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_right_page{ |
||||
|
z-index: 10; |
||||
|
position: relative; |
||||
|
left: calc(var(--pagedjs-bleed-left)*-1); |
||||
|
} |
||||
|
|
||||
|
/* show the margin-box */ |
||||
|
|
||||
|
.pagedjs_margin-top-left-corner-holder, |
||||
|
.pagedjs_margin-top, |
||||
|
.pagedjs_margin-top-left, |
||||
|
.pagedjs_margin-top-center, |
||||
|
.pagedjs_margin-top-right, |
||||
|
.pagedjs_margin-top-right-corner-holder, |
||||
|
.pagedjs_margin-bottom-left-corner-holder, |
||||
|
.pagedjs_margin-bottom, |
||||
|
.pagedjs_margin-bottom-left, |
||||
|
.pagedjs_margin-bottom-center, |
||||
|
.pagedjs_margin-bottom-right, |
||||
|
.pagedjs_margin-bottom-right-corner-holder, |
||||
|
.pagedjs_margin-right, |
||||
|
.pagedjs_margin-right-top, |
||||
|
.pagedjs_margin-right-middle, |
||||
|
.pagedjs_margin-right-bottom, |
||||
|
.pagedjs_margin-left, |
||||
|
.pagedjs_margin-left-top, |
||||
|
.pagedjs_margin-left-middle, |
||||
|
.pagedjs_margin-left-bottom { |
||||
|
box-shadow: 0 0 0 1px inset var(--color-marginBox); |
||||
|
} |
||||
|
|
||||
|
/* uncomment this part for recto/verso book : ------------------------------------ */ |
||||
|
/* |
||||
|
|
||||
|
.pagedjs_pages { |
||||
|
flex-direction: column; |
||||
|
width: 100%; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_first_page { |
||||
|
margin-left: 0; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_page { |
||||
|
margin: 0 auto; |
||||
|
margin-top: 10mm; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page{ |
||||
|
width: calc(var(--pagedjs-bleed-left) + var(--pagedjs-pagebox-width) + var(--pagedjs-bleed-left))!important; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-crop{ |
||||
|
border-color: var(--pagedjs-crop-color); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-middle{ |
||||
|
width: var(--pagedjs-cross-size)!important; |
||||
|
} |
||||
|
|
||||
|
.pagedjs_right_page{ |
||||
|
left: 0; |
||||
|
} |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
|
||||
|
/*--------------------------------------------------------------------------------------*/ |
||||
|
|
||||
|
|
||||
|
|
||||
|
/* uncomment this par to see the baseline : -------------------------------------------*/ |
||||
|
|
||||
|
/* |
||||
|
.pagedjs_pagebox { |
||||
|
--pagedjs-baseline: 22px; |
||||
|
--pagedjs-baseline-position: 5px; |
||||
|
--pagedjs-baseline-color: cyan; |
||||
|
background: linear-gradient(transparent 0%, transparent calc(var(--pagedjs-baseline) - 1px), var(--pagedjs-baseline-color) calc(var(--pagedjs-baseline) - 1px), var(--pagedjs-baseline-color) var(--pagedjs-baseline)), transparent; |
||||
|
background-size: 100% var(--pagedjs-baseline); |
||||
|
background-repeat: repeat-y; |
||||
|
background-position-y: var(--pagedjs-baseline-position); |
||||
|
} */ |
||||
|
|
||||
|
|
||||
|
/*--------------------------------------------------------------------------------------*/ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* Marks (to delete when merge in paged.js) */ |
||||
|
|
||||
|
.pagedjs_marks-crop{ |
||||
|
z-index: 999999999999; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
.pagedjs_bleed-top .pagedjs_marks-crop, |
||||
|
.pagedjs_bleed-bottom .pagedjs_marks-crop{ |
||||
|
box-shadow: 1px 0px 0px 0px var(--pagedjs-crop-shadow); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_bleed-top .pagedjs_marks-crop:last-child, |
||||
|
.pagedjs_bleed-bottom .pagedjs_marks-crop:last-child{ |
||||
|
box-shadow: -1px 0px 0px 0px var(--pagedjs-crop-shadow); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_bleed-left .pagedjs_marks-crop, |
||||
|
.pagedjs_bleed-right .pagedjs_marks-crop{ |
||||
|
box-shadow: 0px 1px 0px 0px var(--pagedjs-crop-shadow); |
||||
|
} |
||||
|
|
||||
|
.pagedjs_bleed-left .pagedjs_marks-crop:last-child, |
||||
|
.pagedjs_bleed-right .pagedjs_marks-crop:last-child{ |
||||
|
box-shadow: 0px -1px 0px 0px var(--pagedjs-crop-shadow); |
||||
|
} |
@ -0,0 +1,128 @@ |
|||||
|
/* Paged.js variables that can be used: |
||||
|
|
||||
|
var(--pagedjs-pagebox-width) for the width of your page |
||||
|
var(--pagedjs-pagebox-height) for the height of your page |
||||
|
|
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
@page{ |
||||
|
size: 152.4mm 228.6mm; |
||||
|
margin: 15mm 20mm 10mm 20mm; |
||||
|
|
||||
|
@top-left{ |
||||
|
content: string(sectionTitle); |
||||
|
width: 100%; |
||||
|
position: absolute; |
||||
|
top: 2mm; |
||||
|
text-align: center; |
||||
|
font-family: monospace; |
||||
|
font-size: 8pt; |
||||
|
color: green; |
||||
|
} |
||||
|
@top-center{ |
||||
|
/* copying a h1 to a running element */ |
||||
|
content: string(contributionTitle); |
||||
|
position: absolute; |
||||
|
top: 7mm; |
||||
|
left: 0; |
||||
|
width: 100%; |
||||
|
text-align: center; |
||||
|
font-family: monospace; |
||||
|
font-size: 8pt; |
||||
|
color: magenta; |
||||
|
} |
||||
|
@bottom-center{ |
||||
|
bottom-top:5mm; |
||||
|
font-family: monospace; |
||||
|
font-size: 8pt; |
||||
|
content: counter(page); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
body{ |
||||
|
font-size: 12pt; |
||||
|
line-height: 16pt; |
||||
|
} |
||||
|
|
||||
|
/* running headers */ |
||||
|
h1{ |
||||
|
string-set: sectionTitle content(text); |
||||
|
page-break-before: always; |
||||
|
} |
||||
|
h2{ |
||||
|
string-set: contributionTitle content(text); |
||||
|
/*position: running content(text); */ /* This "moves" the H2 out of the flow */ |
||||
|
} |
||||
|
|
||||
|
div.section{ |
||||
|
break-before: left; /* makes sure the new section always starts on the right page */ |
||||
|
} |
||||
|
/* section title */ |
||||
|
div.section > h2{ |
||||
|
} |
||||
|
|
||||
|
div.introduction, |
||||
|
div.contribution{ |
||||
|
break-before: left; /* makes sure the new section always starts on the right page */ |
||||
|
} |
||||
|
|
||||
|
/* general elements*/ |
||||
|
h1{ |
||||
|
font-size: 37pt; |
||||
|
line-height: 1.4; |
||||
|
margin: 0; |
||||
|
color: green; |
||||
|
word-break: normal; |
||||
|
} |
||||
|
h2{ |
||||
|
margin: 0 0 32pt 0; |
||||
|
page-break-before: always; |
||||
|
color: magenta; |
||||
|
text-align: center; |
||||
|
} |
||||
|
h3, h4, h5, h6{ |
||||
|
margin: 0 0 16pt 0; |
||||
|
} |
||||
|
p{ |
||||
|
margin: 0 0 16pt 0; |
||||
|
} |
||||
|
.thumb{ |
||||
|
/* image caption */ |
||||
|
font-size: 10pt; |
||||
|
line-height: 1.25; |
||||
|
margin: 24pt 16pt 16pt 16pt; |
||||
|
page-break-inside: avoid; |
||||
|
} |
||||
|
img{ |
||||
|
position: relative; |
||||
|
display: block; |
||||
|
max-width: 100mm; |
||||
|
height: auto; |
||||
|
margin: 0 0 8pt 0; |
||||
|
} |
||||
|
pre{ |
||||
|
font-size: 8pt; |
||||
|
line-height: 1.8; |
||||
|
white-space: normal; |
||||
|
margin: 16pt 16pt; |
||||
|
} |
||||
|
table{ |
||||
|
width: 100%; |
||||
|
} |
||||
|
sup{ |
||||
|
line-height: 0; |
||||
|
} |
||||
|
a, |
||||
|
a:visited, |
||||
|
a:active, |
||||
|
a:hover{ |
||||
|
color: inherit; |
||||
|
text-decoration: none; |
||||
|
font-weight: bold; |
||||
|
} |
||||
|
|
||||
|
/* specific details */ |
||||
|
a.external{ |
||||
|
word-break: break-all; |
||||
|
} |
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,12 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<link href="css/print.css" rel="stylesheet" type="text/css" media="print"> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div id="wrapper"> |
||||
|
{{ publication_unfolded }} |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,15 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<script src="js/paged.js" type="text/javascript"></script> |
||||
|
<script src="js/paged.polyfill.js" type="text/javascript"></script> |
||||
|
<link href="css/interface.css" rel="stylesheet" type="text/css"> |
||||
|
<link href="css/print.css" rel="stylesheet" type="text/css" media="print"> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div id="wrapper"> |
||||
|
{{ publication_unfolded }} |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,151 @@ |
|||||
|
import urllib.request |
||||
|
import os |
||||
|
import re |
||||
|
import json |
||||
|
import jinja2 |
||||
|
|
||||
|
def API_request(url): |
||||
|
""" |
||||
|
url = API request url (string) |
||||
|
data = { 'query': |
||||
|
'pages' : |
||||
|
pageid : { |
||||
|
'links' : { |
||||
|
'?' : '?' |
||||
|
'title' : 'pagename' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
""" |
||||
|
response = urllib.request.urlopen(url).read() |
||||
|
data = json.loads(response) |
||||
|
|
||||
|
# Save response as JSON to be able to inspect API call |
||||
|
json_file = f'{ pagename }.json' |
||||
|
print('Saving JSON:', json_file) |
||||
|
with open(json_file, 'w') as out: |
||||
|
out.write(json.dumps(data, indent=4)) |
||||
|
out.close() |
||||
|
|
||||
|
return data |
||||
|
|
||||
|
def download_media(html, images): |
||||
|
""" |
||||
|
html = string (HTML) |
||||
|
images = list of filenames (str) |
||||
|
""" |
||||
|
# check if 'images/' already exists |
||||
|
if not os.path.exists('images'): |
||||
|
os.makedirs('images') |
||||
|
|
||||
|
# download media files |
||||
|
for filename in images: |
||||
|
filename = filename.replace(' ', '_') # safe filenames |
||||
|
|
||||
|
# check if the image is already downloaded |
||||
|
# if not, then download the file |
||||
|
if not os.path.isfile(f'images/{ filename }'): |
||||
|
|
||||
|
# first we search for the full filename of the image |
||||
|
url = f'{ wiki }/api.php?action=query&list=allimages&aifrom={ filename }&format=json' |
||||
|
response = urllib.request.urlopen(url).read() |
||||
|
data = json.loads(response) |
||||
|
|
||||
|
# we select the first search result |
||||
|
# (assuming that this is the image we are looking for) |
||||
|
image = data['query']['allimages'][0] |
||||
|
|
||||
|
# then we download the image |
||||
|
image_url = image['url'] |
||||
|
image_filename = image['name'] |
||||
|
print('Downloading:', image_filename) |
||||
|
image_response = urllib.request.urlopen(image_url).read() |
||||
|
|
||||
|
# and we save it as a file |
||||
|
image_path = f'images/{ image_filename }' |
||||
|
out = open(image_path, 'wb') |
||||
|
out.write(image_response) |
||||
|
out.close() |
||||
|
|
||||
|
import time |
||||
|
time.sleep(3) # do not overload the server |
||||
|
|
||||
|
# replace src link |
||||
|
image_path = f'images/{ filename }' |
||||
|
html = re.sub(rf'src="/book/images/.*{ filename }"', f'src="{ image_path }"', html) |
||||
|
|
||||
|
return html |
||||
|
|
||||
|
def clean_up(html): |
||||
|
""" |
||||
|
html = string (HTML) |
||||
|
""" |
||||
|
html = re.sub(r'\[.*edit.*\]', '', html) # remove the [edit] |
||||
|
html = re.sub(r'href="/book/index.php?title=.*?"', 'href="#"', html) # remove the internal links |
||||
|
return html |
||||
|
|
||||
|
def parse_page(pagename): |
||||
|
""" |
||||
|
pagename = string |
||||
|
html = string (HTML) |
||||
|
""" |
||||
|
parse = f'{ wiki }/api.php?action=parse&page={ pagename }&pst=True&format=json' |
||||
|
data = API_request(parse) |
||||
|
# print(json.dumps(data, indent=4)) |
||||
|
if 'parse' in data: |
||||
|
html = data['parse']['text']['*'] |
||||
|
images = data['parse']['images'] |
||||
|
html = download_media(html, images) |
||||
|
html = clean_up(html) |
||||
|
else: |
||||
|
html = None |
||||
|
|
||||
|
return html |
||||
|
|
||||
|
def save(html, pagename): |
||||
|
""" |
||||
|
html = string (HTML) |
||||
|
pagename = string |
||||
|
""" |
||||
|
if html: |
||||
|
|
||||
|
# save final page that will be used with PagedJS |
||||
|
template_file = open('template.html').read() |
||||
|
template = jinja2.Template(template_file) |
||||
|
html = template.render(publication_unfolded=publication_unfolded, title=pagename) |
||||
|
|
||||
|
html_file = f'{ pagename }.html' |
||||
|
print('Saving HTML:', html_file) |
||||
|
with open(html_file, 'w') as out: |
||||
|
out.write(html) |
||||
|
out.close() |
||||
|
|
||||
|
# save extra html page for debugging |
||||
|
template_file = open('template.debug.html').read() |
||||
|
template = jinja2.Template(template_file) |
||||
|
html = template.render(publication_unfolded=publication_unfolded, title=pagename) |
||||
|
|
||||
|
html_file = f'{ pagename }.debug.html' |
||||
|
print('Saving HTML:', html_file) |
||||
|
with open(html_file, 'w') as out: |
||||
|
out.write(html) |
||||
|
out.close() |
||||
|
|
||||
|
def update_material_now(pagename): |
||||
|
""" |
||||
|
pagename = string |
||||
|
publication_unfolded = string (HTML) |
||||
|
""" |
||||
|
publication_unfolded = parse_page(pagename) |
||||
|
|
||||
|
return publication_unfolded |
||||
|
|
||||
|
# --- |
||||
|
|
||||
|
wiki = 'https://possiblebodies.constantvzw.org/book' # remove tail slash '/' |
||||
|
pagename = 'Unfolded' |
||||
|
|
||||
|
publication_unfolded = update_material_now(pagename) # download the latest version of the page |
||||
|
save(publication_unfolded, pagename) # save the page to file |
||||
|
|
Loading…
Reference in new issue