Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate useful description for OpenGraph/oEmbed links #176

Open
imagejan opened this issue Jun 16, 2021 · 0 comments
Open

Generate useful description for OpenGraph/oEmbed links #176

imagejan opened this issue Jun 16, 2021 · 0 comments

Comments

@imagejan
Copy link
Member

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 -%}

@ctrueden ctrueden added this to the post-production milestone Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants