From cc57df8f4ca875eca1f6e0760df05f55fd3f953e Mon Sep 17 00:00:00 2001 From: Mariano Montone <marianomontone@gmail.com> Date: Fri, 11 May 2018 18:39:36 -0300 Subject: [PATCH] Fix urls when serving --- Makefile | 3 ++- layout/templates/layout_2018.html | 26 +++++++++++++------------- server.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 server.py diff --git a/Makefile b/Makefile index 1349d91..ccc937b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ all: generate serve: - cd output; python -m SimpleHTTPServer + #cd output; python -m SimpleHTTPServer + cd output; python ../server.py static: cp -r content/static output/static diff --git a/layout/templates/layout_2018.html b/layout/templates/layout_2018.html index 31744ad..c46c012 100644 --- a/layout/templates/layout_2018.html +++ b/layout/templates/layout_2018.html @@ -6,14 +6,14 @@ <title>{{title}}</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700" rel="stylesheet" type="text/css"> - <link href="./static/css/layout_2018.css" rel="stylesheet" type="text/css"> + <link href="/layout_2018.css" rel="stylesheet" type="text/css"> {{#styles}} <link href="{{location}}" rel="stylesheet" type="text/css"> {{/styles}} </head> <body> <nav class="navbar navbar-expand-md fixed-top navbar-dark navigation"> - <a class="navbar-brand" href="./index.html"> + <a class="navbar-brand" href="/"> <img width="30px" height="30px" src="/static/imgs/lisplogo.png" /> Common-Lisp.net</a> @@ -24,41 +24,41 @@ <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item"> - <a class="nav-link" href="./about/">About</a> + <a class="nav-link" href="/about/">About</a> </li> <li class="nav-item dropdown"> <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Get started <span class="caret"></span></a> <div class="dropdown-menu" role="menu"> - <a class="dropdown-item" href="./downloads/">Download</a> - <a class="dropdown-item" href="./tutorials/">Tutorials</a> + <a class="dropdown-item" href="/downloads/">Download</a> + <a class="dropdown-item" href="/tutorials/">Tutorials</a> </div> </li> <li class="nav-item dropdown"> <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Community <span class="caret"></span></a> <div class="dropdown-menu" role="menu"> <a class="dropdown-item" href="http://mailman.common-lisp.net/cgi-bin/mailman/listinfo">Mailing lists</a> - <a class="dropdown-item" href="./independent-lists/">Independent lists</a> - <a class="dropdown-item" href="./orphaned-mailing-lists/">Orphane lists</a> + <a class="dropdown-item" href="/independent-lists/">Independent lists</a> + <a class="dropdown-item" href="/orphaned-mailing-lists/">Orphane lists</a> </div> </li> <li class="nav-item dropdown"> <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Projects <span class="caret"></span></a> <div class="dropdown-menu" role="menu"> - <a class="dropdown-item" href="./phub/">Projects hub</a> - <a class="dropdown-item" href="./project-intro/">Hosting services</a> - <a class="dropdown-item" href="./orphaned-projects/">Orphaned projects</a> - <a class="dropdown-item" href="./faq/">FAQ</a> + <a class="dropdown-item" href="/phub/">Projects hub</a> + <a class="dropdown-item" href="/project-intro/">Hosting services</a> + <a class="dropdown-item" href="/orphaned-projects/">Orphaned projects</a> + <a class="dropdown-item" href="/faq/">FAQ</a> </div> </li> <li class="nav-item dropdown"> <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Resources <span class="caret"></span></a> <div class="dropdown-menu" role="menu"> <a class="dropdown-item" href="http://www.lispworks.com/documentation/lw50/CLHS/Front/Contents.htm">CLHS</a> - <a class="dropdown-item" href="./tools/">Tools</a> + <a class="dropdown-item" href="/tools/">Tools</a> </div> </li> <li class="nav-item"> - <a class="nav-link" href="./contribute/">Contribute</a> + <a class="nav-link" href="/contribute/">Contribute</a> </li> </ul> </div> diff --git a/server.py b/server.py new file mode 100644 index 0000000..9ce6db6 --- /dev/null +++ b/server.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import SimpleHTTPServer +import SocketServer +import os.path +import sys + +class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def do_GET(self): + possible_name = self.path.strip("/")+'.html' + if self.path == '/': + # default routing, instead of "index.html" + self.path = '/index.html' + elif os.path.isfile(possible_name): + # extensionless page serving + self.path = possible_name + + return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + +Handler = MyRequestHandler + +port = 8000 +if len(sys.argv) > 1: + try: + p = int(sys.argv[1]) + port = p + except ValueError: + print "port value provided must be an integer" + +print "Serving on port {0}".format(port) +server = SocketServer.TCPServer(('0.0.0.0', port), Handler) +server.serve_forever() -- GitLab