Improved Page lik handling

This commit is contained in:
2026-02-02 22:36:38 +01:00
parent 47a8bfa50a
commit 1b6df4a9e4
8 changed files with 245 additions and 130 deletions

View File

@@ -211,6 +211,10 @@ abstract class syntax_plugin_luxtools_abstract extends SyntaxPlugin
try {
$pathConfig = (string)$this->getConf('paths');
$blobsRoot = $this->resolveBlobsRoot();
if ($blobsRoot === '' && $this->isBlobsPath($basePath)) {
$this->renderPageNotLinked($renderer);
return false;
}
if ($blobsRoot !== '') {
$pathConfig = rtrim($pathConfig) . "\n" . $blobsRoot . "\nA> blobs";
}
@@ -222,6 +226,55 @@ abstract class syntax_plugin_luxtools_abstract extends SyntaxPlugin
}
}
/**
* Check if the given path uses the blobs alias.
*/
protected function isBlobsPath(string $path): bool
{
$trimmed = ltrim($path, '/');
return preg_match('/^blobs(\/|$)/', $trimmed) === 1;
}
/**
* Render the "Page not linked" message with copy ID affordance.
*/
protected function renderPageNotLinked(\Doku_Renderer $renderer): void
{
$uuid = $this->getPageUuidSafe();
$text = (string)$this->getLang('pagelink_unlinked');
if ($renderer instanceof \Doku_Renderer_xhtml) {
$renderer->doc .= '<a href="#" class="luxtools-pagelink-copy" data-luxtools-pagelink-copy="1"'
. ' data-uuid="' . hsc($uuid) . '"'
. '>' . hsc($text) . '</a>';
return;
}
$renderer->cdata('[n/a: ' . $text . ']');
}
/**
* Read the current page UUID (if any).
*/
protected function getPageUuidSafe(): string
{
global $ID;
$pageId = is_string($ID) ? $ID : '';
if ($pageId === '') return '';
if (function_exists('cleanID')) {
$pageId = (string)cleanID($pageId);
}
if ($pageId === '') return '';
$depth = (int)$this->getConf('pagelink_search_depth');
if ($depth < 0) $depth = 0;
$pageLink = new PageLink((string)$this->getConf('paths'), $depth);
$uuid = $pageLink->getPageUuid($pageId);
return $uuid ?? '';
}
/**
* Resolve the current page's pagelink folder for the blobs alias.
*