Browse Source

Metadata

imwald
Nuša Pukšič 3 months ago
parent
commit
dbf81cdeca
  1. 2
      src/Controller/DefaultController.php
  2. 9
      src/Util/CommonMark/NostrSchemeExtension/NostrRawNpubParser.php

2
src/Controller/DefaultController.php

@ -351,7 +351,7 @@ class DefaultController extends AbstractController
$key = new Key(); $key = new Key();
$npub = $key->convertPublicKeyToBech32($article->getPubkey()); $npub = $key->convertPublicKeyToBech32($article->getPubkey());
$author = $redisCacheService->getMetadata($npub); $author = $redisCacheService->getMetadata($article->getPubkey());
// set canonical url to this article as article-slug path // set canonical url to this article as article-slug path
$canonical = $this->generateUrl('article-slug', [ $canonical = $this->generateUrl('article-slug', [

9
src/Util/CommonMark/NostrSchemeExtension/NostrRawNpubParser.php

@ -3,6 +3,7 @@
namespace App\Util\CommonMark\NostrSchemeExtension; namespace App\Util\CommonMark\NostrSchemeExtension;
use App\Service\RedisCacheService; use App\Service\RedisCacheService;
use App\Util\NostrKeyUtil;
use League\CommonMark\Parser\Inline\InlineParserInterface; use League\CommonMark\Parser\Inline\InlineParserInterface;
use League\CommonMark\Parser\Inline\InlineParserMatch; use League\CommonMark\Parser\Inline\InlineParserMatch;
use League\CommonMark\Parser\InlineParserContext; use League\CommonMark\Parser\InlineParserContext;
@ -14,7 +15,10 @@ use League\CommonMark\Parser\InlineParserContext;
readonly class NostrRawNpubParser implements InlineParserInterface readonly class NostrRawNpubParser implements InlineParserInterface
{ {
public function __construct(private RedisCacheService $redisCacheService) public function __construct(
private RedisCacheService $redisCacheService,
private NostrKeyUtil $nostrKeyUtil,
)
{ {
} }
@ -28,7 +32,8 @@ readonly class NostrRawNpubParser implements InlineParserInterface
$cursor = $inlineContext->getCursor(); $cursor = $inlineContext->getCursor();
// Get the match and extract relevant parts // Get the match and extract relevant parts
$fullMatch = $inlineContext->getFullMatch(); $fullMatch = $inlineContext->getFullMatch();
$meta = $this->redisCacheService->getMetadata($fullMatch);
$meta = $this->redisCacheService->getMetadata($this->nostrKeyUtil->npubToHex($fullMatch));
// Use shortened npub as default name, from first and last 8 characters of the fullMatch // Use shortened npub as default name, from first and last 8 characters of the fullMatch
$name = substr($fullMatch, 0, 8) . '...' . substr($fullMatch, -8); $name = substr($fullMatch, 0, 8) . '...' . substr($fullMatch, -8);

Loading…
Cancel
Save