From 96b4389f3c1f927beac58c4d3e109f82196b24ff Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sat, 2 Oct 2021 09:20:31 -0600 Subject: [PATCH] Server: Serve from output directory, rather than current directory --- pelican/server.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pelican/server.py b/pelican/server.py index 6ebce876..a08de186 100644 --- a/pelican/server.py +++ b/pelican/server.py @@ -43,6 +43,8 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler): SUFFIXES = ['.html', '/index.html', '/', ''] def translate_path(self, path): + """Translate a /-separated PATH to the local filename syntax.""" + # abandon query parameters path = path.split('?', 1)[0] path = path.split('#', 1)[0] @@ -52,15 +54,20 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler): path = posixpath.normpath(path) words = path.split('/') words = filter(None, words) - path = self.base_path + + return_path = self.directory + # actually care about the defined output directory + if self.base_path: + return_path = os.path.join(return_path, self.base_path) + for word in words: if os.path.dirname(word) or word in (os.curdir, os.pardir): # Ignore components that are not a simple file/directory name continue - path = os.path.join(path, word) + return_path = os.path.join(return_path, word) if trailing_slash: - path += '/' - return path + return_path += os.sep + return return_path def do_GET(self): # cut off a query string