Do os.path.abspath on custom content folders in the app constructor before initialization
If relative paths are used for the content folder then send_from_directory may mistakenly interpret the paths as relative to the main application, instead of the content folder
This commit is contained in:
parent
3ccae5739a
commit
dc882c7237
1 changed files with 5 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -23,19 +24,19 @@ class BlogApp(Flask):
|
||||||
|
|
||||||
img_dir = os.path.join(config.content_dir, 'img')
|
img_dir = os.path.join(config.content_dir, 'img')
|
||||||
if os.path.isdir(img_dir):
|
if os.path.isdir(img_dir):
|
||||||
self.img_dir = img_dir
|
self.img_dir = os.path.abspath(img_dir)
|
||||||
|
|
||||||
css_dir = os.path.join(config.content_dir, 'css')
|
css_dir = os.path.join(config.content_dir, 'css')
|
||||||
if os.path.isdir(css_dir):
|
if os.path.isdir(css_dir):
|
||||||
self.css_dir = css_dir
|
self.css_dir = os.path.abspath(css_dir)
|
||||||
|
|
||||||
fonts_dir = os.path.join(config.content_dir, 'fonts')
|
fonts_dir = os.path.join(config.content_dir, 'fonts')
|
||||||
if os.path.isdir(fonts_dir):
|
if os.path.isdir(fonts_dir):
|
||||||
self.fonts_dir = fonts_dir
|
self.fonts_dir = os.path.abspath(fonts_dir)
|
||||||
|
|
||||||
templates_dir = os.path.join(config.content_dir, 'templates')
|
templates_dir = os.path.join(config.content_dir, 'templates')
|
||||||
if os.path.isdir(templates_dir):
|
if os.path.isdir(templates_dir):
|
||||||
self.template_folder = templates_dir
|
self.template_folder = os.path.abspath(templates_dir)
|
||||||
|
|
||||||
def get_page_metadata(self, page: str) -> dict:
|
def get_page_metadata(self, page: str) -> dict:
|
||||||
if not page.endswith('.md'):
|
if not page.endswith('.md'):
|
||||||
|
|
Loading…
Reference in a new issue