Permalinks changed from id to title slug...
This commit is contained in:
parent
07aa53689e
commit
db4a48d08d
7 changed files with 267 additions and 35 deletions
|
|
@ -86,6 +86,50 @@ function mvlog_read_article_id(string $jobdir): string
|
|||
return mvlog_article_id_is_valid($value) ? $value : '';
|
||||
}
|
||||
|
||||
function mvlog_permalink_slug_from_title(string $title, string $fallback = 'post'): string
|
||||
{
|
||||
$slug = strtr($title, [
|
||||
'æ'=>'ae','Æ'=>'ae','ø'=>'o','Ø'=>'o','å'=>'aa','Å'=>'aa',
|
||||
'ä'=>'ae','Ä'=>'ae','ö'=>'oe','Ö'=>'oe','ü'=>'ue','Ü'=>'ue','ß'=>'ss','ẞ'=>'ss',
|
||||
'č'=>'c','Č'=>'c','ć'=>'c','Ć'=>'c','ž'=>'z','Ž'=>'z','š'=>'s','Š'=>'s','đ'=>'d','Đ'=>'d',
|
||||
]);
|
||||
if (function_exists('iconv')) {
|
||||
$ascii = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $slug);
|
||||
if ($ascii !== false) $slug = $ascii;
|
||||
}
|
||||
$slug = strtolower($slug);
|
||||
$slug = preg_replace('/[^a-z0-9]+/', '-', $slug) ?? '';
|
||||
$slug = trim($slug, '-');
|
||||
return $slug !== '' ? $slug : $fallback;
|
||||
}
|
||||
|
||||
function mvlog_permalink_path_for_article(string $mvlog_root, string $articleId): string
|
||||
{
|
||||
$articleId = strtolower(trim($articleId));
|
||||
if (!mvlog_article_id_is_valid($articleId)) return '/';
|
||||
$dirs = glob(rtrim($mvlog_root, '/') . '/in-dir/*', GLOB_ONLYDIR) ?: [];
|
||||
sort($dirs, SORT_STRING);
|
||||
$used = [];
|
||||
foreach ($dirs as $dir) {
|
||||
if (!is_file($dir . '/.mvlog-permalink')) continue;
|
||||
$id = mvlog_read_article_id($dir);
|
||||
if ($id === '') continue;
|
||||
$fields = mvlog_read_job_data_fields($dir);
|
||||
$title = trim((string)($fields['title'] !== '' ? $fields['title'] : basename($dir)));
|
||||
$base = mvlog_permalink_slug_from_title($title, $id);
|
||||
$slug = $base;
|
||||
if (isset($used[$slug])) $slug = $base . '-' . substr($id, -6);
|
||||
$n = 2;
|
||||
while (isset($used[$slug])) {
|
||||
$slug = $base . '-' . substr($id, -6) . '-' . $n;
|
||||
$n++;
|
||||
}
|
||||
$used[$slug] = true;
|
||||
if ($id === $articleId) return '/post/' . rawurlencode($slug);
|
||||
}
|
||||
return '/';
|
||||
}
|
||||
|
||||
function mvlog_read_job_data_fields(string $jobdir): array
|
||||
{
|
||||
$data = ['title' => '', 'teaser' => '', 'description' => ''];
|
||||
|
|
@ -228,8 +272,9 @@ function try_send_show_notification($articleRefOrJob, $jobdir, $mvlog_root = nul
|
|||
$articleExcerpt = rtrim(substr($articleExcerpt, 0, 497)) . '...';
|
||||
}
|
||||
|
||||
$articleUrl = is_file($jobdir . '/.mvlog-permalink') ? './?id=' . rawurlencode($articleId) : './';
|
||||
$journalUrl = 'https://bubulescu.org/' . (is_file($jobdir . '/.mvlog-permalink') ? '?id=' . rawurlencode($articleId) : '');
|
||||
$articlePath = is_file($jobdir . '/.mvlog-permalink') ? mvlog_permalink_path_for_article($mvlog_root, $articleId) : '/';
|
||||
$articleUrl = '.' . $articlePath;
|
||||
$journalUrl = 'https://bubulescu.org' . $articlePath;
|
||||
|
||||
// Attempt web-push, but never let push failure prevent the journal/Listmonk campaign.
|
||||
$pushOk = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue