Browse Source

Remove newlines and modifiers from thread title

main
discomrade 3 years ago
parent
commit
f7478bc840
  1. 10
      inc/functions.php
  2. 2
      inc/lib/twig/extensions/Extension/Tinyboard.php
  3. 5
      templates/thread.html

10
inc/functions.php

@ -2377,6 +2377,16 @@ function unicodify($body) {
return $body;
}
function end_on_newline($body) {
return strstr($body, "\n", true);
}
// If there is no punctuation before newline, add a full-stop.
// Then replace all newlines/whitespace with a space.
function remove_paragraphs($body) {
return preg_replace("/\s+/",' ', preg_replace("/\b(?=\n*$)/m",'.',$body));
}
function extract_modifiers($body) {
$modifiers = array();

2
inc/lib/twig/extensions/Extension/Tinyboard.php

@ -19,6 +19,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
new Twig_SimpleFilter('capcode', 'capcode'),
new Twig_SimpleFilter('remove_modifiers', 'remove_modifiers'),
new Twig_SimpleFilter('remove_markup', 'remove_markup'),
new Twig_SimpleFilter('end_on_newline', 'end_on_newline'),
new Twig_SimpleFilter('remove_paragraphs', 'remove_paragraphs'),
new Twig_SimpleFilter('hasPermission', 'twig_hasPermission_filter'),
new Twig_SimpleFilter('date', 'twig_date_filter'),
new Twig_SimpleFilter('poster_id', 'poster_id'),

5
templates/thread.html

@ -11,9 +11,10 @@
{% include 'header.html' %}
{% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup|remove_modifiers|remove_markup[:256]|e }}{% endif %}{% endset %}
{% set meta_desc %}{{ thread.body_nomarkup|remove_modifiers|remove_markup|remove_paragraphs[:256]|e }}{% endset %}
{% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup|remove_modifiers|remove_markup|end_on_newline[:256]|e }}{% endif %}{% endset %}
<meta name="description" content="{{ board.url }} - {{ board.title|e }} - {{ meta_subject }}" />
<meta name="description" content="{{ board.url }} - {{ board.title|e }} - {{ meta_desc }}" />
<meta name="twitter:card" value="summary">
<meta property="og:title" content="{{ meta_subject }}" />
<meta property="og:type" content="article" />

Loading…
Cancel
Save