diff --git a/src/Pages/BlogIndexPage.php b/src/Pages/BlogIndexPage.php index e4b5882..9adbeb1 100644 --- a/src/Pages/BlogIndexPage.php +++ b/src/Pages/BlogIndexPage.php @@ -9,6 +9,7 @@ use DanielWebsite\Blog\BlogPostStore; use DanielWebsite\SitemapEntry; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; +use League\CommonMark\Extension\CommonMark\Node\Inline\Link; use League\CommonMark\Node\Block\Paragraph; use League\CommonMark\Node\Query; use League\CommonMark\Parser\MarkdownParser; @@ -42,6 +43,18 @@ protected function build(): void { foreach ( $posts as $post ) { $parsedResult = $parser->parse( $post->markdown ); + // For any links in the first paragraph of a blog post that are + // relative to the blog post, adjust the paths + $links = ( new Query() ) + ->where( Query::type( Link::class ) ) + ->findAll( $parsedResult ); + foreach ( $links as $link ) { + $url = $link->getUrl(); + if ( str_starts_with( $url, './' ) ) { + $link->setUrl( './Blog/' . substr( $url, 2 ) ); + } + } + $firstHeading = ( new Query() ) ->where( Query::type( Heading::class ) ) ->findOne( $parsedResult ); diff --git a/src/Pages/LandingPage.php b/src/Pages/LandingPage.php index 52e4a75..14521dc 100644 --- a/src/Pages/LandingPage.php +++ b/src/Pages/LandingPage.php @@ -9,6 +9,7 @@ use DanielWebsite\Blog\BlogPostStore; use DanielWebsite\SitemapEntry; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; +use League\CommonMark\Extension\CommonMark\Node\Inline\Link; use League\CommonMark\Node\Block\Paragraph; use League\CommonMark\Node\Query; use League\CommonMark\Parser\MarkdownParser; @@ -126,6 +127,18 @@ protected function build(): void { $parsedResult = $parser->parse( $latestPost->markdown ); + // For any links in the first paragraph of a blog post that are + // relative to the blog post, adjust the paths + $links = ( new Query() ) + ->where( Query::type( Link::class ) ) + ->findAll( $parsedResult ); + foreach ( $links as $link ) { + $url = $link->getUrl(); + if ( str_starts_with( $url, './' ) ) { + $link->setUrl( './Blog/' . substr( $url, 2 ) ); + } + } + $firstHeading = ( new Query() ) ->where( Query::type( Heading::class ) ) ->findOne( $parsedResult ); diff --git a/tests/data/Home.html b/tests/data/Home.html index d7dd22a..5585116 100644 --- a/tests/data/Home.html +++ b/tests/data/Home.html @@ -4,7 +4,7 @@ Computer Science and Political Science and graduating magna cum laude in 2024 with a Bachelor of Science degree. As part of my work in Computer Science, I chose to write an honors thesis in my senior year, see here for details. I continued at Tufts for graduate school, graduating in 2025 with a Master of Science in Computer Science degree.
See the links in the navigation bar above for more information about my -experience.
daniel.e.scherzer@gmail.comI also have a blog. You can see a full index of my posts here. My latest blog post is:
As I mentioned in my last blog post, while at ConFoo I and a few +experience.
daniel.e.scherzer@gmail.comI also have a blog. You can see a full index of my posts here. My latest blog post is:
As I mentioned in my last blog post, while at ConFoo I and a few other developers worked on some ideas for adding friendship support to PHP. To be clear, these are just ideas at the moment, but I figured they were worth sharing. Continue reading...