Skip to content

Commit

Permalink
feat: link checker (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored Oct 4, 2024
1 parent 03f4e6b commit 53f54b8
Show file tree
Hide file tree
Showing 31 changed files with 225 additions and 163 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ jobs:
env:
ORAMA_CLOUD_INDEX_ID: ${{ vars.ORAMA_CLOUD_INDEX_ID }}
ORAMA_CLOUD_API_KEY: ${{ secrets.ORAMA_CLOUD_API_KEY }}
run: DENO_FUTURE=1 deno task build
DENO_FUTURE: 1
run: deno task build

- name: Run server
working-directory: _site
run: deno run --no-lock --allow-read=. --allow-net --allow-env server.ts &

- name: Link checker
env:
DOCS_ROOT: "http://localhost:8000"
run: deno run --no-lock --allow-net --allow-env .github/workflows/link_checker.ts

- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/link_checker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { DOMParser } from "jsr:@b-fuze/deno-dom";

const visitedPages = new Set<string>();

const rootURL = new URL(Deno.env.get("DOCS_ROOT")!);
const rootPage = await fetch(rootURL).then((res) => res.text());

visitedPages.add(rootURL);
let hasInvalidHrefs = false;

await traversePage(rootURL, rootPage);

if (hasInvalidHrefs) {
Deno.exit(1);
}

async function traversePage(url: URL, content: string) {
const doc = new DOMParser().parseFromString(content, "text/html");
await Promise.allSettled([...doc.querySelectorAll("a").values()]
.map((a) => {
const href = a.getAttribute("href")?.trim();
if (!href) {
hasInvalidHrefs = true;
console.error(`Empty href on '${url.pathname}': ${a.outerHTML}`);
return;
}

if (href.startsWith("http") || href.startsWith("mailto")) {
return;
}

const aURL = new URL(href, url);
if (aURL.pathname.startsWith("/api")) {
return;
}

if (visitedPages.has(aURL.href)) {
return;
}

visitedPages.add(aURL.href);

return fetch(aURL).then((res) => {
if (res.status === 200) {
if (res.headers.get("content-type")?.includes("text/html")) {
return res.text().then((text) => traversePage(aURL, text));
}
} else {
hasInvalidHrefs = true;
console.error(`${res.status} on '${url.pathname}': ${href}`);
}

return res.body?.cancel();
});
}));
}
4 changes: 4 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deploy/manual/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Now that you've created your first deployment, you can
out what other options you have to deploy your code to Deno Deploy. We're so
excited to see what you'll ship with Deno Deploy!

### <a name="existingproject"></a>Deploy your existing project
### Deploy your existing project

Import a project and run it on the edge it with Deno Deploy.

Expand Down
4 changes: 2 additions & 2 deletions index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function () {
title="Testing in Deno"
description="All about Deno’s built-in test runner for JavaScript or TypeScript code."
linktext="More about Testing"
link="/runtime/manual/basics/testing/"
link="/runtime/fundamentals/testing"
product="runtime"
/>
</div>
Expand Down Expand Up @@ -438,7 +438,7 @@ export default function () {
title="Connect with our community"
description="Get help from the Deno community"
linktext="Learn more"
link="/runtime/manual/help/"
link="/runtime/help"
product="help"
/>
<ContentItem
Expand Down
3 changes: 1 addition & 2 deletions runtime/contributing/building_from_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ oldUrl:

Below are instructions on how to build Deno from source. If you just want to use
Deno you can download a prebuilt executable (more information in the
[`Getting Started`](../../getting_started/installation.md#download-and-install)
chapter).
[`Getting Started`](../getting_started/installation.md) chapter).

## Cloning the Repository

Expand Down
2 changes: 1 addition & 1 deletion runtime/contributing/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Official Docker images for Deno.

## General remarks

- Read the [style guide](/runtime/contribution/style_guide).
- Read the [style guide](/runtime/contributing/style_guide).

- Please don't make [the benchmarks](https://deno.land/benchmarks) worse.

Expand Down
3 changes: 1 addition & 2 deletions runtime/fundamentals/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ sharing code.

:::

See also
[Configuring TypeScript in Deno](/runtime/manual/advanced/typescript/configuration/).
See also [Configuring TypeScript in Deno](../reference/ts_config_migration.md).

## Unstable features

Expand Down
2 changes: 1 addition & 1 deletion runtime/fundamentals/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ to debug the code.

Deno can be debugged using VSCode. This is best done with help from the official
`vscode_deno` extension. Documentation for this can be found
[here](/runtime/manual/references/vscode_deno/#using-the-debugger).
[here](/runtime/reference/vscode#using-the-debugger).

## JetBrains IDEs

Expand Down
Loading

0 comments on commit 53f54b8

Please sign in to comment.