test static gen

thumb
km0 2 years ago
parent f73274c13f
commit 7e7931e40c

2
.gitignore vendored

@ -5,3 +5,5 @@
/static/html
/static/video
venv/
old_boat.py

@ -11,7 +11,6 @@ import json
# FUNCTIONS
def list_files(folder, remove_ext=False):
''' Read all the functions in a folder '''
names = []
@ -47,7 +46,7 @@ def get_md_contents(filename, directory='./contents'):
def render_home():
with open('render.html', 'r+w') as f:
with open('render.html', 'w') as f:
# get the basic info of the website from the /contents/home.md file
meta, content = get_md_contents("home.md")
projects_list = []
@ -72,32 +71,40 @@ def render_home():
}
f.write(render_template("home.html", **home))
# FLASK APP
base_url = "~kamo"
projects = 'projects'
# create flask application
app = Flask(__name__,
static_url_path=f'/soupboat/{base_url}/static',
static_folder=f'/soupboat/{base_url}/static')
# Markdown(app, extensions=['extra'])
# app.jinja_env.extend(jinja2_highlight_cssclass = 'codehilite')
class PrefixMiddleware(object):
def __init__(self, app, prefix=""):
self.app = app
self.prefix = prefix
def __call__(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.prefix):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :]
environ["SCRIPT_NAME"] = self.prefix
return self.app(environ, start_response)
else:
start_response("404", [("Content-Type", "text/plain")])
return ["This url does not belong to the app.".encode()]
# add the base_url variable to all the flask templates
@app.context_processor
def set_base_url():
return dict(base_url=base_url)
projects = 'projects'
# create flask application
app = Flask(__name__)
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/~kamo')
# Homepage
@app.route(f"/{base_url}/")
@app.route("/")
def home_page():
return send_from_directory(app.root_path, 'render.html')
# For generic pages we can include a common template and change only the contents
@app.route(f"/{base_url}/<slug>/")
@app.route("/<slug>/")
def dynamic_page(slug=None):
# meta is a dictionary that contains all the attributes in the markdown file (ex: title, description, soup, etc)
# content is the body of the md file aka the text content
@ -107,7 +114,7 @@ def dynamic_page(slug=None):
# Single project
@app.route(f"/{base_url}/projects/<project>/")
@app.route("/projects/<project>/")
def p_info(project=None):
meta, content = get_md_contents("documentation.md",
f"./{projects}/{project}")
@ -117,18 +124,19 @@ def p_info(project=None):
return render_template(template, **meta, content=content)
@app.route(f'/{base_url}/projects/<project>/<path:filename>')
@app.route('/projects/<project>/<path:filename>')
def sendStaticFiles(project, filename):
return send_from_directory(app.root_path + f'/projects/{project}/', filename, conditional=True)
@app.route(f'/{base_url}/hook/', methods=['GET', 'POST'])
@app.route('/hook/', methods=['GET', 'POST'])
def pull():
if request.method == 'POST':
subprocess.call(['sh', '/home/kamo/public_html/update.sh'])
with open('log.txt', 'a') as f:
f.write(request.form['payload'])
print(request.form['payload'])
render_home()
@ -136,5 +144,10 @@ def pull():
return 'GET method not supported'
@app.route('/api/render')
def render():
render_home()
return 'rendered'
# RUN
app.run(port="3132")
app.run(port="3132", debug=True)

File diff suppressed because it is too large Load Diff

@ -1,58 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %} - {{ title }} {% endblock %}</title>
<!-- style -->
<link rel="icon" href="{{url_for('static', filename='favicon.ico')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='font/font.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/categories.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/highlight.css')}}" />
<!-- script -->
{% block head %}{% endblock %}
<!-- Meta -->
<!-- Primary Meta Tags -->
<meta name="title" content="{{ title }}">
<meta name="description" content="Documentation workout for the Experimental Publishing master at Piet Zwart Institute, Rotterdam">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://hub.xpub.nl/soupboat/~kamo/">
<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="Documentation workout for the Experimental Publishing master at Piet Zwart Institute, Rotterdam">
<meta property="og:image" content="https://hub.xpub.nl/soupboat/~kamo/static/img/sharknado.jpg">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://hub.xpub.nl/soupboat/~kamo/">
<meta property="twitter:title" content="{{title}}">
<meta property="twitter:description" content="Documentation workout for the Experimental Publishing master at Piet Zwart Institute, Rotterdam">
<meta property="twitter:image" content="https://hub.xpub.nl/soupboat/~kamo/static/img/sharknado.jpg">
</head>
<body>
<nav>
{% block nav %} {% endblock %}
</nav>
<header>
<h1 class="title">{{ title }}</h1>
{% block header %} {% endblock %}
</header>
<main>{%block content%} {% endblock %}</main>
</body>
</html>

@ -1,9 +0,0 @@
{% extends "project.html" %}
{% block cover%}
<figure class='cards'>
{% for card in cards %}
<img src="{{url_for('static', filename='img/' + card)}}"/>
{%endfor%}
</figure>
{% endblock %}

@ -1,80 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kamo {% block title %} - {{ title }} {% endblock %}</title>
<!-- style -->
<link rel="icon" href="{{url_for('static', filename='favicon.ico')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='font/font.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/home.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/categories.css')}}" />
<!-- script -->
</head>
<body>
<main class="content">
<div class="homepage-intro">
<h2 class="title">{{ title }}</h2>
<div class="description">{{content|safe}}</div>
</div>
<table id="table">
{% for project in projects %}
<tr>
<td class="title">
<h3 class="title--name">
<a href="projects/{{project.slug}}/" class="stretched-link">
{{project.title}}
</a>
</h3>
<div class="title--description">
{% if project.description %}
{{ project.description }}
{% endif %}
</div>
</td>
<td class="links">
{% if project.url %}
<a href="{{project.url}}">project</a>
{% endif %}
{% if project.pad %}
<a href="{{project.pad}}">pad</a>
{% endif %}
{% if project.git %}
<a href="{{project.git}}">git</a>
{% endif %}
{% if project.links %}
{% for link in project.links %}
<a href="{{link.url}}">{{link.title}}</a>
{% endfor %}
{% endif%}
</td>
<td class="categories">
{% for category in project.categories %}
<span class="tag" data-tag="{{category}}">{{category}}</span>
{% endfor %}
</td>
<td class="date">
{% if project.date %}
<span>{{project.date}}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</main>
</body>
</html>

@ -1,42 +0,0 @@
{% extends "base.html" %}
<!-- Additional styles and scripts -->
{% block head %}
{% if css %}
<link
rel="stylesheet"
href="{{url_for('static', filename='css/' +css)}}"
/>
{% endif %}
{% if script %}
<script
src="{{url_for('static', filename='js/' + script)}}"
defer ></script>
{% endif %}
{% endblock %}
<!-- Title -->
{% block title %}
{{title}}
{% endblock %}
{% block nav %}
<a href="/soupboat/{{base_url}}/">Back</a>
{% endblock %}
<!-- Contents in the body -->
{% block content%}
{% if cover %}
<img class='cover' alt='{{cover_alt}}' src="{{url_for('static', filename='img/' + cover)}}"/>
{% endif %}
{{ content|safe }}
{% endblock %}

@ -1,123 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ title }} </title>
<!-- style -->
<link rel="icon" href="{{url_for('static', filename='favicon.ico')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='font/font.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/project.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/categories.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/highlight.css')}}" />
{% if css %}
<link
rel="stylesheet"
href="{{url_for('static', filename='css/' +css)}}"
/>
{% endif %}
<!-- script -->
<script src="{{url_for('static', filename='js/mover.js')}}" defer ></script>
{% if script %}
<script
src="{{url_for('static', filename='js/' + script)}}"
defer ></script>
{% endif %}
<!-- Meta -->
{% if description %}
<meta name="description" content="{{ description }}">
<meta property="og:description" content="{{description}}">
<meta property="twitter:description" content="{{description}}">
{% endif %}
{% if cover %}
<meta property="og:image" content="https://hub.xpub.nl{{url_for('static', filename='img/' + cover)}}">
<meta property="twitter:image" content="https://hub.xpub.nl{{url_for('static', filename='img/' + cover)}}">
{% endif %}
</head>
<body>
<nav>
<div class="content-wrapper">
<a href="/soupboat/~kamo/" class="return"></a>
<h2 class="title"> {{title }} </h2>
<div class="date"> {{ date}} </div>
</div>
</nav>
<header class="project--header">
{% block cover %}
{% if cover and cover_alt %}
<figure class="header--cover">
<img src="{{url_for('static', filename='img/' + cover)}}" alt="{{cover_alt}}" />
</figure>
{% endif %}
{% endblock %}
<h1 class="header--title" style="transform: translate(-50%, -50%)" data-mover="2">{{ title }}</h1>
<div class="header--links">
{% if project %}
<a href="{{url_for('static', filename='html/' + project + '/')}}" class="goto-link"> go to the project </a>
{% endif %}
{% if url %}
<a href="{{url}}" target="__blank">go to project</a>
{% endif %}
{% if pad %}
<a href="{{pad}}" target="__blank">pad</a>
{% endif %}
{% if git %}
<a href="{{git}}" target="__blank">git</a>
{% endif %}
{% if links %}
{% for link in links %}
<a href="{{link.url}}" target="__blank">{{link.title}}</a>
{% endfor %}
{% endif%}
</div>
<div class="header--categories">
{% for category in categories %}
<span class="tag" data-tag="{{category}}" data-mover="1"
style="transform: translate({{range(10,90) | random }}vw, {{range(10,90) | random }}vh)"
>
{{category}}
</span>
{% endfor %}
</div>
</header>
<main class="project--content">
{{content|safe}}
</main>
</body>
</html>

@ -1,42 +1,18 @@
{% extends "base.html" %}
<!-- Additional styles and scripts -->
{% block head %}
{% if css %}
<link
rel="stylesheet"
href="{{url_for('static', filename='css/' +css)}}"
/>
{% endif %}
{% if script %}
<script
src="{{url_for('static', filename='js/' + script)}}"
defer ></script>
{% endif %}
{% endblock %}
{% block head %} {% if css %}
<link rel="stylesheet" href="{{url_for('static', filename='css/' +css)}}" />
{% endif %} {% if script %}
<script src="{{url_for('static', filename='js/' + script)}}" defer></script>
{% endif %} {% endblock %}
<!-- Title -->
{% block title %}
{{title}}
{% endblock %}
{% block nav %}
<a href="/soupboat/{{base_url}}/">Back</a>
{% block title %} {{title}} {% endblock %} {% block nav %}
<a href="{{url_for('home_page')}}">Back</a>
{% endblock %}
<!-- Contents in the body -->
{% block content%}
{% if cover %}
<img class='cover' alt='{{cover_alt}}' src="{{url_for('static', filename='img/' + cover)}}"/>
{% endif %}
{{ content|safe }}
{% endblock %}
{% block content%} {% if cover %}
<img class="cover" alt="{{cover_alt}}" src="{{url_for('static', filename='img/' + cover)}}" />
{% endif %} {{ content|safe }} {% endblock %}

Loading…
Cancel
Save