feed: compile regex once #1

Merged
r merged 1 commits from knoflook/lumbunglib:master into master 2022-03-03 05:54:53 +00:00

View File

@ -12,7 +12,8 @@ import jinja2
import requests
from bs4 import BeautifulSoup
from slugify import slugify
from re import sub
from re import compile as re_compile
yamlre = re_compile('"')
def write_etag(feed_name, feed_data):
@ -119,12 +120,12 @@ def sanitize_yaml (frontmatter):
#some fields are lists
l = []
for i in v:
i = sub('"', '\\"', i)
i = yamlre.sub('\\"', i)
l.append(i)
frontmatter[k] = l
else:
v = sub('"', '\\"', v)
v = yamlre.sub('\\"', v)
frontmatter[k] = v
return frontmatter