Skip to content

Generate useful description for OpenGraph/oEmbed links #176

Open
@imagejan

Description

@imagejan

When one-boxing a link to the new website on the forum, e.g. in this post, the description currently reads:

ImageJ is an open source image processing program designed for scientific multidimensional images.

It's possible to specify the description with description: in the front matter, but ideally we should improve the default description to be the same that is also used in the search (see this Gitter discussion).

@ctrueden suggests translating the Python code here:

def first_sentence(lines):
def good(line):
if line.startswith('#'): return False # ignore headers
if re.match('^[=-]+$', line): return False # ignore section dividers
return True
s = ''.join(line for line in lines if good(line))
s = re.sub('<[^>]*>', '', s) # strip HTML
s = re.sub('{%[^%]*%}', '', s) # strip Liquid tags
s = re.sub('\[([^]]*)\]\([^\)]*\)', '\\1', s) # strip Markdown links
s = re.sub('\*+\\s*([^\*]*)\\s*\*+', '\\1', s) # strip emphasis
s = re.sub('\\s\\s*', ' ', s) # unify whitespace
dot = s.find('. ')
if dot >= 0: s = s[:dot+1] # cut down to first sentence
return s.strip()

... to Liquid and call it from here:

{%- else -%}
{{ site.description }}
{%- endif -%}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions