Skip to content

Commit

Permalink
fixed formatting of <meta> tags
Browse files Browse the repository at this point in the history
also:
- added config option `author`
- added config option `robots`
- added `p` and `center` to the allowed square-bracket HTML tags
  • Loading branch information
marzer committed May 18, 2021
1 parent d439b84 commit b818a1a
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
2 changes: 1 addition & 1 deletion poxy/data/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.3.2
80 changes: 78 additions & 2 deletions poxy/fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class CustomTags(object):
'''
__double_tags = re.compile(
r'\[\s*('
+ r'span|div|aside|code|pre|h1|h2|h3|h4|h5|h6|em|strong|b|i|u|li|ul|ol'
+ r'p|center|span|div|aside|code|pre|h1|h2|h3|h4|h5|h6|em|strong|b|i|u|li|ul|ol'
+ r')(.*?)\s*\](.*?)\[\s*/\1\s*\]',
re.I | re.S
)
__single_tags = re.compile(
r'\[\s*(/?(?:'
+ r'img|span|div|aside|code|pre|emoji'
+ r'p|img|span|div|aside|code|pre|emoji'
+ r'|(?:parent_)?set_(?:parent_)?(?:name|class)'
+ r'|(?:parent_)?(?:add|remove)_(?:parent_)?class'
+ r'|br|li|ul|ol|(?:html)?entity)'
Expand Down Expand Up @@ -716,6 +716,8 @@ def __call__(self, doc, context):

return changed



#=======================================================================================================================
# empty tags
#=======================================================================================================================
Expand All @@ -731,3 +733,77 @@ def __call__(self, doc, context):
soup.destroy_node(tag)
changed = True
return changed



#=======================================================================================================================
# <head> tags
#=======================================================================================================================

class HeadTags(object):
'''
Injects poxy-specific tags into the document's <head> block.
'''

@classmethod
def __append(cls, doc, name, attrs):
doc.head.append(' ')
doc.new_tag(name, parent=doc.head, attrs=attrs)
doc.head.append('\n')

def __call__(self, doc, context):

# <meta> tags
if 1:
meta = []

# name
if context.name:
if r'twitter:title' not in context.meta_tags:
meta.append({ r'name' : r'twitter:title', r'content' : context.name})
meta.append({ r'property' : r'og:title', r'content' : context.name})
meta.append({ r'itemprop' : r'name', r'content' : context.name})

# author
if context.author:
if r'author' not in context.meta_tags:
meta.append({ r'name' : r'author', r'content' : context.author})
meta.append({ r'property' : r'article:author', r'content' : context.author})

# description
if context.description:
if r'description' not in context.meta_tags:
meta.append({ r'name' : r'description', r'content' : context.description})
if r'twitter:description' not in context.meta_tags:
meta.append({ r'name' : r'twitter:description', r'content' : context.description})
meta.append({ r'property' : r'og:description', r'content' : context.description})
meta.append({ r'itemprop' : r'description', r'content' : context.description})

# robots
if not context.robots:
if r'robots' not in context.meta_tags:
meta.append({ r'name' : r'robots', r'content' : r'noindex, nofollow'})
if r'googlebot' not in context.meta_tags:
meta.append({ r'name' : r'googlebot', r'content' : r'noindex, nofollow'})

# misc
if r'format-detection' not in context.meta_tags:
meta.append({ r'name' : r'format-detection', r'content' : r'telephone=no'})
if r'generator' not in context.meta_tags:
meta.append({ r'name' : r'generator', r'content' : rf'Poxy v{".".join(context.version)}'})
if r'referrer' not in context.meta_tags:
meta.append({ r'name' : r'referrer', r'content' : r'no-referrer-when-downgrade'})

# additional user-specified meta tags
for name, content in context.meta_tags.items():
meta.append({ r'name' : name, r'content' : content})

for tag in meta:
self.__append(doc, r'meta', tag)

# stylesheets and scripts
self.__append(doc, r'link', {r'href' : r'poxy.css', r'rel' : r'stylesheet'})
self.__append(doc, r'script', {r'src' : r'poxy.js' })
self.__append(doc, r'script', {r'src' : context.jquery.name })

return True
17 changes: 14 additions & 3 deletions poxy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ def __init__(self, config, key, input_dir):




#=======================================================================================================================
# project context
#=======================================================================================================================
Expand All @@ -859,6 +858,7 @@ class Context(object):
__config_schema = Schema(
{
Optional(r'aliases') : {str : str},
Optional(r'author') : str,
Optional(r'autolinks') : {str : str},
Optional(r'badges') : {str : FixedArrayOf(str, 2, name=r'badges') },
Optional(r'code_blocks') : _CodeBlocks.schema,
Expand All @@ -881,6 +881,7 @@ class Context(object):
Optional(r'name') : str,
Optional(r'navbar') : ValueOrArray(str, name=r'navbar'),
Optional(r'private_repo') : bool,
Optional(r'robots') : bool,
Optional(r'show_includes') : bool,
Optional(r'sources') : _Sources.schema,
Optional(r'tagfiles') : {str : str},
Expand Down Expand Up @@ -1143,6 +1144,12 @@ def __init__(self, config_path, output_dir, threads, cleanup, verbose, mcss_dir,
self.name = config['name'].strip()
self.verbose_value(r'Context.name', self.name)

# project author
self.author = ''
if 'author' in config:
self.author = config['author'].strip()
self.verbose_value(r'Context.author', self.author)

# project description (PROJECT_BRIEF)
self.description = ''
if 'description' in config:
Expand Down Expand Up @@ -1279,10 +1286,14 @@ def __init__(self, config_path, output_dir, threads, cleanup, verbose, mcss_dir,
self.meta_tags = {}
for k, v in _extract_kvps(config, 'meta_tags', allow_blank_values=True).items():
self.meta_tags[k] = v
if self.description and 'description' not in self.meta_tags:
self.meta_tags['description'] = self.description
self.verbose_value(r'Context.meta_tags', self.meta_tags)

# robots (<meta>)
self.robots = True
if 'robots' in config:
self.robots = bool(config['robots'])
self.verbose_value(r'Context.robots', self.robots)

# inline namespaces for old versions of doxygen
self.inline_namespaces = copy.deepcopy(_Defaults.inline_namespaces)
if 'inline_namespaces' in config:
Expand Down
9 changes: 1 addition & 8 deletions poxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,6 @@ def _preprocess_doxyfile(context):
df.append(r'##! M_LINKS_NAVBAR1 = ')
df.append(r'##! M_LINKS_NAVBAR2 = ')
df.append(r'##!')
if not df.contains(r'M_HTML_HEADER'):
df.append(r'##! M_HTML_HEADER = ''\\')
for k, v in context.meta_tags.items():
df.append(rf'##! <meta name="{k}" content="{v}"> ''\\')
df.append(r'##! <link href="poxy.css" rel="stylesheet"/> ''\\')
df.append(rf'##! <script src="{context.jquery.name}"></script> ''\\')
df.append(r'##! <script src="poxy.js"></script>')
df.append(r'##!')
if not df.contains(r'M_PAGE_FINE_PRINT'):
df.append(r'##! M_PAGE_FINE_PRINT = ''\\')
top_row = []
Expand Down Expand Up @@ -766,6 +758,7 @@ def _postprocess_html(context):
, fixers.Links()
, fixers.CustomTags()
, fixers.EmptyTags()
, fixers.HeadTags()
)
context.verbose(rf'Post-processing {len(files)} HTML files...')
if threads > 1:
Expand Down
4 changes: 2 additions & 2 deletions poxy/soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def __exit__(self, type, value, traceback):
self.smooth()
self.flush()

def new_tag(self, name, parent=None, string=None, class_=None, index=None, before=None, after=None, **kwargs):
tag = self.__doc.new_tag(name, **kwargs)
def new_tag(self, tag_name, parent=None, string=None, class_=None, index=None, before=None, after=None, **kwargs):
tag = self.__doc.new_tag(tag_name, **kwargs)
if (string is not None):
if (tag.string is not None):
tag.string.replace_with(string)
Expand Down

0 comments on commit b818a1a

Please sign in to comment.