Fix compile-time link validation and add tag page links
- Restore HTML link extraction in LinkValidator (removed in a83634d
under the false premise that post bodies are raw markdown; they
are HTML rendered by NimblePublisher at compile time). The missing
regex made extract_links/1 find zero links, silently disabling
compile-time validation.
- Support /blog/{blog_id}/tag/{tag} links: validate blog ID,
require non-empty tag (tags are user-defined, e.g. pi.dev).
- Fix invalid links in two posts: tag/Pi.dev -> tag/pi.dev,
2026-07-13-synthetic-tdd.md -> synthetic-tdd.
- Fix test warnings: use Plug.Test deprecation, unused import,
runtime-defined TestBlogValid module.
- Add regression tests for HTML extraction and tag page links.
This commit is contained in:
@@ -59,7 +59,7 @@ defmodule Blogex.BlogIntegrationTest do
|
||||
""")
|
||||
|
||||
[{TestBlogValid, _bytecode}] = Code.compile_file(tmp_file, __ENV__.file)
|
||||
assert TestBlogValid.title() == "Test Blog"
|
||||
assert apply(TestBlogValid, :title, []) == "Test Blog"
|
||||
|
||||
File.rm!(tmp_file)
|
||||
end
|
||||
|
||||
@@ -13,6 +13,22 @@ defmodule Blogex.LinkValidatorTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "extracts internal blog links from HTML body" do
|
||||
body =
|
||||
~s(<p>Check out <a href="/blog/engineering/hello-world">hello world</a> and <a href="/blog/releases/v1-0-0">release v1</a>.</p>)
|
||||
|
||||
assert LinkValidator.extract_links(body) == [
|
||||
"/blog/engineering/hello-world",
|
||||
"/blog/releases/v1-0-0"
|
||||
]
|
||||
end
|
||||
|
||||
test "extracts tag page links from HTML body" do
|
||||
body = ~s(<p>See <a href="/blog/engineering/tag/pi.dev">pi.dev posts</a>.</p>)
|
||||
|
||||
assert LinkValidator.extract_links(body) == ["/blog/engineering/tag/pi.dev"]
|
||||
end
|
||||
|
||||
test "ignores external links" do
|
||||
body = "See [GitHub](https://github.com) and [internal](/blog/engineering/post)."
|
||||
|
||||
@@ -132,6 +148,25 @@ defmodule Blogex.LinkValidatorTest do
|
||||
assert LinkValidator.validate_link("/blog/engineering/post#section") == :ok
|
||||
end
|
||||
|
||||
test "allows tag page links" do
|
||||
assert LinkValidator.validate_link("/blog/engineering/tag/pi.dev") == :ok
|
||||
assert LinkValidator.validate_link("/blog/releases/tag/v1") == :ok
|
||||
end
|
||||
|
||||
test "allows tag page links with fragments" do
|
||||
assert LinkValidator.validate_link("/blog/engineering/tag/pi.dev#top") == :ok
|
||||
end
|
||||
|
||||
test "rejects tag page link with empty tag" do
|
||||
assert LinkValidator.validate_link("/blog/engineering/tag/") ==
|
||||
{:error, "empty tag in tag link"}
|
||||
end
|
||||
|
||||
test "rejects unknown blog ID in tag page link" do
|
||||
assert LinkValidator.validate_link("/blog/unknown/tag/pi.dev") ==
|
||||
{:error, "unknown blog ID: unknown"}
|
||||
end
|
||||
|
||||
test "rejects non-blog path" do
|
||||
assert LinkValidator.validate_link("/about") ==
|
||||
{:error, "not a blog link: /about"}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
defmodule Blogex.RegistryTest do
|
||||
use ExUnit.Case
|
||||
|
||||
import Blogex.Test.PostBuilder
|
||||
alias Blogex.Registry
|
||||
|
||||
defmodule AlphaBlog do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
defmodule Blogex.RouterTest do
|
||||
use ExUnit.Case
|
||||
use Plug.Test
|
||||
import Plug.Test
|
||||
|
||||
import Blogex.Test.PostBuilder
|
||||
alias Blogex.Test.FakeBlog
|
||||
|
||||
Reference in New Issue
Block a user