unicode issues when running from php fpm

This commit is contained in:
Sean Dockray 2020-06-05 12:08:30 +10:00
parent c802904abc
commit ef75acd1b3
1 changed files with 13 additions and 5 deletions

View File

@ -15,6 +15,7 @@ vars = {
"syllabus_db": "https://www.notion.so/memoryspace/594e40c85f2844b5911f14e7db21850f?v=2a2e8a86e8a74d29844f5eef41d18b3f",
"syllabus_title": "Pirate Care",
"token_v2": "Find the value of 'token_v2' in your browser cookies when logged into Notion",
"hugo_path": "hugo",
"hugo_site_path": "/mnt/d/dev/websites/arche-syllabus-test", # The Hugo site
"website_path": "/mnt/d/tmp/notion",
"base_url": "http://127.0.0.1:8000"
@ -34,10 +35,16 @@ prefixes = {
def get_value(name, default=False):
""" Variables can be set as environment variable or in command line """
if hasattr(args, name.lower()) and getattr(args, name.lower()) is not None:
print('CLI:', name, getattr(args, name.lower()))
if not name.lower() == "token_v2":
print('CLI:', name, getattr(args, name.lower()))
else:
print('CLI:', name, "XXXX")
return getattr(args, name.lower())
elif name.upper() in os.environ:
print('env:', name, os.environ[name.upper()])
if not name.lower() == "token_v2":
print('env:', name, os.environ[name.upper()])
else:
print('CLI:', name, "XXXX")
return os.environ[name.upper()]
else:
print('default:', name, default)
@ -68,11 +75,12 @@ def rmrf(path, keep_root=False):
def cmd(parts, cwd=None, env=None):
""" Executes a shell command and returns the output """
print(f"Command: {' '.join(parts)} ({cwd})")
return subprocess.check_output(parts, cwd=cwd, env=env, universal_newlines=True).strip()
return subprocess.call(parts, cwd=cwd, env=env, universal_newlines=True)
def hugo(hugo_site_path, dest, hugo_environment='gitea', base_url=None):
""" builds the website to "dest" using "tmp" as an intermediate location """
global HUGO_PATH
rmrf(dest, keep_root=True)
try:
os.makedirs(dest, exist_ok=True)
@ -83,7 +91,7 @@ def hugo(hugo_site_path, dest, hugo_environment='gitea', base_url=None):
if base_url:
env["HUGO_PARAMS_BASEURL"] = base_url
# run the hugo command
hugo_output = cmd(['hugo', '-e', hugo_environment, '-d', dest, '--noTimes'], cwd=hugo_site_path, env=env)
hugo_output = cmd([HUGO_PATH, '-e', hugo_environment, '-d', dest, '--noTimes'], cwd=hugo_site_path, env=env)
def get_record_text(post):
@ -105,7 +113,7 @@ def get_record_text(post):
text += "---"
else:
prefix = prefixes.get(child.type, "")
text += prefix + child.title + "\n\n"
text += prefix + str(child.title.encode('utf-8')) + "\n\n"
text = re.sub('`bib:([a-zA-Z0-9-]+)`', r'![](bib:\1)', text)
return text