mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
Utilities+Meta: Check icons in markdown-check
We use the environment variable SERENITY_SOURCE_DIR to resolve and check icon links. This is a bit inconvenient as SERENITY_SOURCE_DIR needs to be set correctly before invoking the markdown checker, but as we use it through the check-markdown script anyways, I think it's not a problem.
This commit is contained in:
parent
4ef1bedc38
commit
084347becc
2 changed files with 20 additions and 4 deletions
|
@ -18,4 +18,9 @@ if [ -z "${MARKDOWN_CHECK_BINARY:-}" ] ; then
|
||||||
MARKDOWN_CHECK_BINARY="Build/lagom/markdown-check"
|
MARKDOWN_CHECK_BINARY="Build/lagom/markdown-check"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$SERENITY_SOURCE_DIR" ] ; then
|
||||||
|
SERENITY_SOURCE_DIR=$(pwd -P)
|
||||||
|
export SERENITY_SOURCE_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
find AK Base Documentation Kernel Meta Ports Tests Userland -path 'Ports/*/*' -prune -o -type f -name '*.md' -print0 | xargs -0 "${MARKDOWN_CHECK_BINARY}" README.md
|
find AK Base Documentation Kernel Meta Ports Tests Userland -path 'Ports/*/*' -prune -o -type f -name '*.md' -print0 | xargs -0 "${MARKDOWN_CHECK_BINARY}" README.md
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <LibMarkdown/Visitor.h>
|
#include <LibMarkdown/Visitor.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static bool is_missing_file_acceptable(String const& filename)
|
static bool is_missing_file_acceptable(String const& filename)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +77,15 @@ public:
|
||||||
Vector<FileLink> const& file_links() const { return m_file_links; }
|
Vector<FileLink> const& file_links() const { return m_file_links; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MarkdownLinkage() = default;
|
MarkdownLinkage()
|
||||||
|
{
|
||||||
|
auto const* source_directory = getenv("SERENITY_SOURCE_DIR");
|
||||||
|
if (source_directory != nullptr) {
|
||||||
|
m_serenity_source_directory = source_directory;
|
||||||
|
} else {
|
||||||
|
warnln("The environment variable SERENITY_SOURCE_DIR was not found. Link checking inside Serenity's filesystem will fail.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual RecursionDecision visit(Markdown::Heading const&) override;
|
virtual RecursionDecision visit(Markdown::Heading const&) override;
|
||||||
virtual RecursionDecision visit(Markdown::Text::LinkNode const&) override;
|
virtual RecursionDecision visit(Markdown::Text::LinkNode const&) override;
|
||||||
|
@ -84,6 +93,8 @@ private:
|
||||||
HashTable<String> m_anchors;
|
HashTable<String> m_anchors;
|
||||||
Vector<FileLink> m_file_links;
|
Vector<FileLink> m_file_links;
|
||||||
bool m_has_invalid_link { false };
|
bool m_has_invalid_link { false };
|
||||||
|
|
||||||
|
String m_serenity_source_directory;
|
||||||
};
|
};
|
||||||
|
|
||||||
MarkdownLinkage MarkdownLinkage::analyze(Markdown::Document const& document)
|
MarkdownLinkage MarkdownLinkage::analyze(Markdown::Document const& document)
|
||||||
|
@ -190,10 +201,10 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
|
||||||
return RecursionDecision::Recurse;
|
return RecursionDecision::Recurse;
|
||||||
}
|
}
|
||||||
if (url.scheme() == "file") {
|
if (url.scheme() == "file") {
|
||||||
// TODO: Resolve relative to $SERENITY_SOURCE_DIR/Base/, though we might refer to build-only files like binaries.
|
// TODO: Check more possible links other than icons.
|
||||||
|
|
||||||
if (url.path().starts_with("/res/icons/")) {
|
if (url.path().starts_with("/res/icons/")) {
|
||||||
outln("Not checking icon link {}", href);
|
auto file = String::formatted("{}/Base{}", m_serenity_source_directory, url.path());
|
||||||
|
m_file_links.append({ file, String(), StringCollector::from(*link_node.text) });
|
||||||
return RecursionDecision::Recurse;
|
return RecursionDecision::Recurse;
|
||||||
}
|
}
|
||||||
outln("Not checking local link {}", href);
|
outln("Not checking local link {}", href);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue