Extract metadata extraction method
This commit is contained in:
@ -6,16 +6,17 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from i2p2www import BLOG_DIR
|
from i2p2www import BLOG_DIR
|
||||||
|
from i2p2www import helpers
|
||||||
|
|
||||||
|
|
||||||
SUPPORTED_METATAGS = {
|
BLOG_METATAGS = {
|
||||||
'author': u'I2P devs',
|
'author': u'I2P devs',
|
||||||
'category': None,
|
'category': None,
|
||||||
'date': None,
|
'date': None,
|
||||||
'excerpt': u'',
|
'excerpt': u'',
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_METATAGS = [
|
BLOG_LIST_METATAGS = [
|
||||||
'category',
|
'category',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -108,11 +109,4 @@ def render_blog_post(slug):
|
|||||||
return publish_parts(source=rendered_content, source_path=BLOG_DIR, writer_name="html")
|
return publish_parts(source=rendered_content, source_path=BLOG_DIR, writer_name="html")
|
||||||
|
|
||||||
def get_metadata_from_meta(meta):
|
def get_metadata_from_meta(meta):
|
||||||
metaLines = meta.split('\n')
|
return helpers.get_metadata_from_meta(meta, BLOG_METATAGS, BLOG_LIST_METATAGS)
|
||||||
ret = {}
|
|
||||||
for metaTag in SUPPORTED_METATAGS:
|
|
||||||
metaLine = [s for s in metaLines if 'name="%s"' % metaTag in s]
|
|
||||||
ret[metaTag] = metaLine[0].split('content="')[1].split('"')[0] if len(metaLine) > 0 else SUPPORTED_METATAGS[metaTag]
|
|
||||||
if metaTag in LIST_METATAGS and ret[metaTag]:
|
|
||||||
ret[metaTag] = [s.strip() for s in ret[metaTag].split(',')]
|
|
||||||
return ret
|
|
||||||
|
@ -9,6 +9,16 @@ def get_for_page(items, page, per_page):
|
|||||||
to_item = page*per_page
|
to_item = page*per_page
|
||||||
return items[from_item:to_item]
|
return items[from_item:to_item]
|
||||||
|
|
||||||
|
def get_metadata_from_meta(meta, supported_metatags, list_metatags):
|
||||||
|
metaLines = meta.split('\n')
|
||||||
|
ret = {}
|
||||||
|
for metaTag in supported_metatags:
|
||||||
|
metaLine = [s for s in metaLines if 'name="%s"' % metaTag in s]
|
||||||
|
ret[metaTag] = metaLine[0].split('content="')[1].split('"')[0] if len(metaLine) > 0 else supported_metatags[metaTag]
|
||||||
|
if metaTag in list_metatags and ret[metaTag]:
|
||||||
|
ret[metaTag] = [s.strip() for s in ret[metaTag].split(',')]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# General helper classes
|
# General helper classes
|
||||||
|
Reference in New Issue
Block a user