Skip to content

Fetch links to Markdown files - #14

Merged
lfoppiano merged 4 commits into
masterfrom
feature/get-markdown-links
Oct 1, 2026
Merged

lfoppiano merged 4 commits into
masterfrom
feature/get-markdown-links

Conversation

@lfoppiano

@lfoppiano lfoppiano commented Sep 30, 2026 •

Copy link
Copy Markdown

This PR adds the retrieval of links to markdown files:

  1. reading the http header Link
  2. from the LINK@/href
  3. rel=describedby is not used, only the type is used

The type check is strengthen to support encoding suffix.

@lfoppiano

Copy link
Copy Markdown
Author

I tested on a couple of WAT from (CC-MAIN-20260917025921-20260917055921-0099{7,8,9}.warc.wat.gz), we have around 70 new links per WAT file.

@sebastian-nagel sebastian-nagel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @lfoppiano! Looks excellent!

Nothing to criticize. Only one suggestions to further improve the PR: remove the condition restriction the addition of HTTP header links to only Markdown documents. Include also canonical links, alternate language pages, feeds - everything accepted by addOutLinks(...). See inline comments.

if (httpHeaderNames == null) {
return;
}
JSONArray links = new JSONArray();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea to fill the HTTP header links into a JSON structure ...

}
}
if (links.length() > 0) {
addOutLinks(context, outLinks, baseUrl, links);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and pass them to the addOutLinks(...).

link.put(name, val);
}
}
if (link.has("type") && matchesMediaType(link.getString("type"), "text/markdown")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since addOutLinks(...) already filters type=text/markdown, why not remove this condition? - and update the Javadoc.

Of course, this would also allow canonical links, alternate language pages, and (if configured) RSS/Atom feeds. But that would be a further improvement! And the rather complex decision which links to accept, would be in a single place (code block). Unwanted links (CSS stylesheets, dns-prefetch, pingbacks, etc.) are reliably filtered out by addOutLinks(...).

if (extractFeed && link.has("type")) {
String type = link.getString("type");
if ("application/atom+xml".equals(type) || "application/rss+xml".equals(type)) {
if (matchesMediaType(type, "application/atom+xml")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement!

@lfoppiano

Copy link
Copy Markdown
Author

@sebastian-nagel thanks for the feedback! It was very helpful to learn more about this job. I've updated the code following your suggestions. I also added an additional check to enforce the presence of the rel parameter, the RFC indicate it's mandatory.

@sebastian-nagel sebastian-nagel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lfoppiano
lfoppiano merged commit 6fdbd33 into master Oct 1, 2026
3 checks passed
@lfoppiano
lfoppiano deleted the feature/get-markdown-links branch October 1, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WATSampleOutlinks: sample markdown links from HTML header <link> elements

2 participants