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