From 699bf610169daeb47bdcc894eb13fa1a706dc50b Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 22 Dec 2020 16:01:53 +0100 Subject: Switch to static Web App --- README.md | 28 ++--------- config.json | 11 +++++ main.py | 49 ------------------- manage.py | 45 ++++++++++++++++++ static/css/style.css | 111 ------------------------------------------- static/img/favicon.ico | Bin 6715 -> 0 bytes templates/index.html | 40 ---------------- webroot/css/xengineering.css | 111 +++++++++++++++++++++++++++++++++++++++++++ webroot/favicon.ico | Bin 0 -> 6715 bytes webroot/index.html | 28 +++++++++++ webroot/template.html | 28 +++++++++++ 11 files changed, 228 insertions(+), 223 deletions(-) create mode 100644 config.json delete mode 100755 main.py create mode 100755 manage.py delete mode 100644 static/css/style.css delete mode 100644 static/img/favicon.ico delete mode 100644 templates/index.html create mode 100644 webroot/css/xengineering.css create mode 100644 webroot/favicon.ico create mode 100644 webroot/index.html create mode 100644 webroot/template.html diff --git a/README.md b/README.md index 34376ff..a9f6052 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,15 @@ # Web Template -A template project for dynamic web applications. +A template project for mixed static / dynamic web applications. ## Usage -### Just try it -``` -# Install Flask and waitress with your linux package manager. -# Otherwise you could use pip: -pip3 install --user Flask waitress - -git clone https://github.com/xengineering/web-template.git -cd web-template -python3 main.py - -# switch to another terminal - -curl http://localhost:8080 # test with curl -firefox http://localhost:8080 # test with firefox -``` +Just follow these steps: +1. Edit config.json +2. Edit the files in the webroot folder +3. Upload the webroot to your target server with ```python3 manage.py deploy``` via SSH / rsync ### Use it for your Project ``` @@ -37,10 +26,3 @@ git fetch template git merge template/master ``` - -## Used Technologies - -- [Python 3](https://www.python.org/) -- [Python Flask](https://palletsprojects.com/p/flask/) -- [Waitress WSGI Server](https://github.com/Pylons/waitress) -- Pure HTML, CSS and JavaScript diff --git a/config.json b/config.json new file mode 100644 index 0000000..1ad14b1 --- /dev/null +++ b/config.json @@ -0,0 +1,11 @@ + +{ + "deployments":[ + { + "host":"example.com", + "username":"exampleuser", + "webroot":"/srv/http/example.com/public/" + } + ] +} + diff --git a/main.py b/main.py deleted file mode 100755 index 0cd7c61..0000000 --- a/main.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/python3 - - -""" - web-template - A Template Project for dynamic Web Applications. - - Copyright (C) 2020 xengineering - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -""" - - -from waitress import serve -from flask import Flask, render_template, current_app - - -app = Flask(__name__) - - -@app.route('/') -def index(): - return render_template('index.html') - - -@app.route('/static/css/') -def css(css_file): - return current_app.send_static_file("css/{}".format(css_file)) - - -@app.route('/favicon.ico') -def favicon(): - return current_app.send_static_file("img/favicon.ico") - - -if __name__ == '__main__': - serve(app, listen='*:8080') # production server / bind to port - #serve(app, unix_socket='/run/web-template/unix.sock') # production server / unix domain socket - #app.run() # debug server - NOT FOR PRODUCTION! diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..50249e5 --- /dev/null +++ b/manage.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + + +import sys +import subprocess +import json + + +CONFIG_PATH = "./config.json" + + +def main(): + + if len(sys.argv) != 2: + print("Provide exactly one parameter") + sys.exit(1) + + cfg = read_config() + + command = sys.argv[1] + + if command == "deploy": + for deployment in cfg["deployments"]: + subprocess.call( + "rsync -av ./webroot/ {0}@{1}:{2}".format( + deployment["username"], + deployment["host"], + deployment["webroot"] + ), + shell=True + ) + else: + print("Unknown command") + +def read_config(): + with open(CONFIG_PATH, "r") as f: + content = f.read() + return json.loads(content) + +if __name__ == "__main__": + main() + + +# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab + diff --git a/static/css/style.css b/static/css/style.css deleted file mode 100644 index fd92176..0000000 --- a/static/css/style.css +++ /dev/null @@ -1,111 +0,0 @@ - - -/* - web-template - A Template Project for dynamic Web Applications. - - Copyright (C) 2020 xengineering - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - - -/* - General Stuff -*/ - -* { - box-sizing: border-box; /* Include padding and border in the element's total width and height */ -} - -body { - margin: 0; /* avoid ugly white margin */ - font-family: Arial, Helvetica, sans-serif; /* select a nice font */ -} - -.menu { - background-color: black; -} - -.content { - background-color: white; -} - -.menu a { - color: lightgray; - text-decoration: none; /* disable ugly underlined links */ -} - -/* How should the link behave if the mouse is over this item? */ -.menu a:hover { - background-color: lightgray; - color: black; -} - - - -/* - Default Geometry / Geometry for Phones ('Mobile First Development') -*/ - -.content { - padding-left: 20px; - padding-right: 20px; - text-align: justify; -} - -.menu a { - display: block; - padding: 16px; - text-align: center; -} - - - -/* - Geometry for Tablets -*/ - -@media only screen and (min-width: 600px) { - /* empty --> same rules as for phones */ -} - - - -/* - Geometry for Desktops -*/ - -@media only screen and (min-width: 768px) { - - .menu { - height: 100%; - width: 200px; - position: fixed; /* position fixed in top left corner (with offset) */ - top: 0px; /* disable the offset from top left corner */ - } - - .menu a { - text-align: left; - } - - .content { - margin-left: 200px; /* transparent margin on the left for .menu */ - } - - .content *{ /* everything inside the content container */ - max-width: 960px; /* maximum width on desktops should be 960 px */ - margin-left: auto; /* center it with margin */ - margin-right: auto; /* center it with margin */ - } -} diff --git a/static/img/favicon.ico b/static/img/favicon.ico deleted file mode 100644 index 969b451..0000000 Binary files a/static/img/favicon.ico and /dev/null differ diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 67e2d78..0000000 --- a/templates/index.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - Web Template - - - - - - -
-
-

Web Template

-

- Lorem ipsum. -

-
-
- - diff --git a/webroot/css/xengineering.css b/webroot/css/xengineering.css new file mode 100644 index 0000000..1e14b72 --- /dev/null +++ b/webroot/css/xengineering.css @@ -0,0 +1,111 @@ + + +/* + web-template - A Template Project for dynamic Web Applications. + + Copyright (C) 2020 xengineering + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + + +/* + General Stuff +*/ + +* { + box-sizing: border-box; /* Include padding and border in the element's total width and height */ +} + +body { + margin: 0; /* avoid ugly white margin */ + font-family: Arial, Helvetica, sans-serif; /* select a nice font */ +} + +.xmenu { + background-color: black; +} + +.xcontent { + background-color: white; +} + +.xmenu a { + color: lightgray; + text-decoration: none; /* disable ugly underlined links */ +} + +/* How should the link behave if the mouse is over this item? */ +.xmenu a:hover { + background-color: lightgray; + color: black; +} + + + +/* + Default Geometry / Geometry for Phones ('Mobile First Development') +*/ + +.xcontent { + padding-left: 20px; + padding-right: 20px; + text-align: justify; +} + +.xmenu a { + display: block; + padding: 16px; + text-align: center; +} + + + +/* + Geometry for Tablets +*/ + +@media only screen and (min-width: 600px) { + /* empty --> same rules as for phones */ +} + + + +/* + Geometry for Desktops +*/ + +@media only screen and (min-width: 768px) { + + .xmenu { + height: 100%; + width: 200px; + position: fixed; /* position fixed in top left corner (with offset) */ + top: 0px; /* disable the offset from top left corner */ + } + + .xmenu a { + text-align: left; + } + + .xcontent { + margin-left: 200px; /* transparent margin on the left for .xmenu */ + } + + .xcontent *{ /* everything inside the content container */ + max-width: 960px; /* maximum width on desktops should be 960 px */ + margin-left: auto; /* center it with margin */ + margin-right: auto; /* center it with margin */ + } +} diff --git a/webroot/favicon.ico b/webroot/favicon.ico new file mode 100644 index 0000000..969b451 Binary files /dev/null and b/webroot/favicon.ico differ diff --git a/webroot/index.html b/webroot/index.html new file mode 100644 index 0000000..59922a2 --- /dev/null +++ b/webroot/index.html @@ -0,0 +1,28 @@ + + + + + + + Web Template + + + + + + + + + +
+ HOME +
+ +
+

Web Template

+
+ + + + + diff --git a/webroot/template.html b/webroot/template.html new file mode 100644 index 0000000..b8ce99a --- /dev/null +++ b/webroot/template.html @@ -0,0 +1,28 @@ + + + + + + + Web Template + + + + + + + + + +
+ HOME +
+ +
+

Web Template

+
+ + + + + -- cgit v1.2.3-70-g09d2