diff options
author | Florian Dold <florian@dold.me> | 2021-04-21 21:07:18 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-04-21 21:07:18 +0200 |
commit | 2b84f3bd5de3a500b63193924bea2f3dfd0c9afd (patch) | |
tree | 08d5a2bd354ab7849d731eabe7b132429b6d2225 /talermerchantdemos/blog/content.py | |
parent | 4356540b2eb12b2c307270566b0b4ce969e12c60 (diff) | |
download | taler-merchant-demos-2b84f3bd5de3a500b63193924bea2f3dfd0c9afd.tar.gz taler-merchant-demos-2b84f3bd5de3a500b63193924bea2f3dfd0c9afd.tar.bz2 taler-merchant-demos-2b84f3bd5de3a500b63193924bea2f3dfd0c9afd.zip |
common base template, new logo and lots of cleanup
Diffstat (limited to 'talermerchantdemos/blog/content.py')
-rw-r--r-- | talermerchantdemos/blog/content.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/talermerchantdemos/blog/content.py b/talermerchantdemos/blog/content.py index 00064df..ba2fcbe 100644 --- a/talermerchantdemos/blog/content.py +++ b/talermerchantdemos/blog/content.py @@ -49,8 +49,8 @@ ARTICLES = {} # @param extra_file collection of extra files associated with the # article, like images and sounds. # @param lang language of the arcile -def add_article(slug, title, teaser, main_file, extra_files, lang='en'): - if (not (lang in ARTICLES)): +def add_article(slug, title, teaser, main_file, extra_files, lang="en"): + if not (lang in ARTICLES): ARTICLES[lang] = OrderedDict() ARTICLES[lang][slug] = Article(slug, title, teaser, main_file, extra_files, lang) @@ -71,8 +71,10 @@ def get_image_file(image): # @param article the article filename. # @return the path to the article HTML file. def get_article_file(article): - filex = resource_filename("talermerchantdemos", article.main_file) - return os.path.basename(filex) + filex = resource_filename( + "talermerchantdemos", article.main_file, + ) + return os.path.abspath(filex) ## @@ -88,7 +90,7 @@ def get_article_file(article): # specified. def add_from_html(resource_name, lang): res = resource_stream("talermerchantdemos", resource_name) - soup = BeautifulSoup(res, 'html.parser') + soup = BeautifulSoup(res, "html.parser") res.close() title_el = soup.find("h2") if title_el is None: @@ -103,9 +105,9 @@ def add_from_html(resource_name, lang): paragraphs = soup.find_all("p") if len(paragraphs) > 0: teaser = paragraphs[0].get_text() - if (len(paragraphs) > 1) and (len (teaser) < 100): + if (len(paragraphs) > 1) and (len(teaser) < 100): teaser2 = paragraphs[1].get_text() - if (len(teaser2) > len(teaser)): + if len(teaser2) > len(teaser): teaser = teaser2 else: LOGGER.warning("Cannot extract teaser from '%s'", resource_name) @@ -119,21 +121,23 @@ def add_from_html(resource_name, lang): # We require that any image whose access is regulated is src'd # as "<slug>/data/img.png". We also need to check if the <slug> # component actually matches the article's slug - if re_proc.match(img['src']): - if img['src'].split(os.sep)[2] == slug: + if re_proc.match(img["src"]): + if img["src"].split(os.sep)[2] == slug: LOGGER.info( - "extra file for %s is %s" % - (slug, os.path.basename(img['src'])) + "extra file for %s is %s" % (slug, os.path.basename(img["src"])) ) - extra_files.append(os.path.basename(img['src'])) + extra_files.append(os.path.basename(img["src"])) else: - LOGGER.warning("Image src and slug don't match: '%s' != '%s'" \ - % (img['src'].split(os.sep)[2], slug)) + LOGGER.warning( + "Image src and slug don't match: '%s' != '%s'" + % (img["src"].split(os.sep)[2], slug) + ) add_article(slug, title, teaser, resource_name, extra_files, lang) + for l in listdir(resource_filename("talermerchantdemos", "blog/articles/")): # Filter by active languages, otherwise this takes quite a while to load... - if l in { "en", "de", "sv", "es" }: + if l in {"en", "de", "sv", "es"}: LOGGER.info("importing %s" % l) - for a in listdir(resource_filename ("talermerchantdemos", "blog/articles/" + l)): + for a in listdir(resource_filename("talermerchantdemos", "blog/articles/" + l)): add_from_html("blog/articles/" + l + "/" + a, l) |