Skip to content

Commit

Permalink
fix: broken links & improve link checker (#147)
Browse files Browse the repository at this point in the history
* fix: broken links
---------

Co-authored-by: Call Delegation <106365423+calldelegation@users.noreply.github.com>
  • Loading branch information
sarahschwartz and calldelegation authored Dec 27, 2023
1 parent 8a94cbd commit c686cbc
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 66 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@ on:
deployment_status

jobs:
check-links:
check-guides-links:
uses: FuelLabs/github-actions/.github/workflows/next-links.yml@master
with:
status: ${{ github.event.deployment_status.state }}
preview-url: ${{ github.event.deployment_status.environment_url }}
folder-path: docs/guides/docs

final-link-check:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Set up env
run: |
python -m venv env
source env/bin/activate
- name: Install dependencies
run: |
pip install linkchecker
- name: Check All Links
run: |
linkchecker --check-extern --no-warnings --ignore-url=crates.io --ignore-url=127.0.0.1 --ignore-url=block-explorer-v2 --ignore-url=localhost: --ignore-url=infura.io --ignore-url=chainsecurity.com --ignore-url=-indexer.fuel.network --ignore-url=beta-4.fuel.network/graphql ${{ github.event.deployment_status.environment_url }}/sitemap.xml
2 changes: 1 addition & 1 deletion docs/guides/docs/quickstart/building-a-frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ action={{

To make it easier to interact with our contract we use `fuels typegen` command to interpret the output ABI JSON from our contract, and generate Typescript definitions based on it. This JSON was created when we executed the `forc build` command to compile our Sway Contract into binary.

If you see the folder `fuel-project/counter-contract/out` you will be able to see the ABI JSON there. If you want to learn more, read the [ABI spec](https://fuellabs.github.io/fuel-specs/master/protocol/abi).
If you see the folder `fuel-project/counter-contract/out` you will be able to see the ABI JSON there. If you want to learn more, read the [ABI spec](/docs/specs/abi/).

Inside the `fuel-project/frontend` directory run:

Expand Down
20 changes: 20 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ const nextConfig = {
destination: '/guides/nightly/:slug*',
permanent: true,
},
{
source: '/docs/fuels-rs/contributing/',
destination: '/docs/fuels-rs/contributing/contributing/',
permanent: true,
},
{
source: '/docs/wallet/contributing/',
destination: '/docs/wallet/contributing/running-locally/',
permanent: true,
},
{
source: '/docs/wallet/dev/',
destination: '/docs/wallet/dev/getting-started/',
permanent: true,
},
{
source: '/docs/indexer/getting-started/',
destination: '/docs/indexer/getting-started/dependencies',
permanent: true,
},
];
},
typescript: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prettier:check": "prettier --check .",
"prettier:format": "prettier --write .",
"start": "next start",
"patch:wallet": "node scripts/wallet-examples.mjs",
"patch:wallet": "node scripts/wallet-patch-fixes/index.mjs",
"test:guides": "npx playwright test tests/test.spec.ts",
"test:guides:debug": "DEBUG=pw:api npx playwright test tests/test.spec.ts",
"ts:check": "tsc --noEmit",
Expand Down
64 changes: 64 additions & 0 deletions scripts/wallet-patch-fixes/download-link.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { readFileSync, writeFileSync } from 'fs';
import { EOL } from 'os';
import { join } from 'path';

const constantsPath = join(
process.cwd(),
'docs/fuels-wallet/packages/docs/src/constants.ts'
);
const nightlyConstantsPath =
'docs/nightly/fuels-wallet/packages/docs/src/constants.ts';

const downloadVarName = 'DOWNLOAD_LINK';

function getWalletVersion(isNightly) {
const file = readFileSync(
join(
process.cwd(),
`docs/${
isNightly ? 'nightly/' : ''
}fuels-wallet/packages/app/package.json`
),
'utf-8'
);
const json = JSON.parse(file);
return json.version;
}

function handleConstantsFile(filePath, isNightly) {
const file = readFileSync(filePath, 'utf8');

let lines = file.split(EOL);
let start;
let end;

for (let i = 0; i < lines.length; i++) {
if (!start) {
if (lines[i].includes(downloadVarName)) {
start = i;
}
} else if (!end) {
if (lines[i].endsWith(';')) {
end = i;
}
}
}

const walletVersion = getWalletVersion(isNightly);

if (start !== undefined && end !== undefined && walletVersion) {
let modifiedContent = `export const DOWNLOAD_LINK = 'https://next-wallet.fuel.network/app/fuel-wallet-${walletVersion}.zip';`;
lines.splice(start, end - start + 1, modifiedContent);
const newFileContent = lines.join(EOL);
writeFileSync(filePath, newFileContent, 'utf8');

console.log('File modified successfully');
} else {
console.log('Variable definition not found or incomplete.');
}
}

export default function patchFixWalletDownloadLink() {
handleConstantsFile(constantsPath, false);
handleConstantsFile(nightlyConstantsPath, true);
}
9 changes: 9 additions & 0 deletions scripts/wallet-patch-fixes/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import patchFixWalletDownloadLink from './download-link.mjs';
import patchFixWalletExamples from './wallet-examples.mjs';

function main() {
patchFixWalletExamples();
patchFixWalletDownloadLink();
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ function processDirectory(directory) {
});
}

processDirectory(examplesPath);
processDirectory(nightlyExamplesPath);
export default function patchFixWalletExamples() {
processDirectory(examplesPath);
processDirectory(nightlyExamplesPath);
}
51 changes: 2 additions & 49 deletions src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,12 @@ import { cssObj } from '@fuel-ui/css';
import type { LinkProps } from '@fuel-ui/react';
import { Link as FuelLink } from '@fuel-ui/react';
import NextLink from 'next/link';
import { useRouter } from 'next/router';

function replaceInternalLinks(href: string, base: string) {
if (
href.startsWith('https://fuellabs.github.io') &&
!href.startsWith('https://fuellabs.github.io/block-explorer-v2/') &&
!href.includes('LICENSE')
) {
href = href
.replace('https://fuellabs.github.io', '')
.replace('/master/', '/')
.replace('.html', '')
.replace('/nightly', '')
.replace('/index', '/')
.replace('sway/book/', 'sway/');
href = `/docs${href}`;

if (href.includes('fuels-ts/guide/')) {
href = href.replace('fuels-ts/guide/', 'fuels-ts/');
}

const isSwayVersion = href.match(/sway\/(v.+)\/forc/);
if (isSwayVersion) {
const version = isSwayVersion[1];
href = href.replace(`sway/${version}/forc`, 'forc');
}
}
if (href.startsWith('../')) {
href = href.replace('../', `/${base}/`);
}

// TODO: fix this at source
href = href.replace(
'docs/fuel-docs/quickstart/developer-quickstart',
'/guides/quickstart/'
);

return href;
}

export function Link(props: LinkProps) {
const router = useRouter();
const base = router.asPath.split('/').splice(1, 2).join('/');
let href = replaceInternalLinks(props.href as string, base);

if (href?.startsWith('./')) {
href = `/${base}${href.slice(1)}`;
}

return href?.startsWith('http') ? (
return props.href?.startsWith('http') ? (
<FuelLink {...props} isExternal css={styles.link} />
) : (
<NextLink href={href} passHref legacyBehavior>
<NextLink href={props.href ?? ''} passHref legacyBehavior>
<FuelLink {...props} css={styles.link} />
</NextLink>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/VersionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function VersionDropdown({ isNightly }: { isNightly: boolean }) {
const splitPath = router.asPath.split('/');
const isDoc =
router.asPath.includes('docs') && !router.asPath.includes('/intro/');
const bookIndex = isNightly ? 3 : 2;
const bookIndex = isNightly && router.asPath.includes('nightly') ? 3 : 2;
return (
<Dropdown isOpen={opened} onOpenChange={setOpened}>
<Dropdown.Trigger
Expand Down
6 changes: 5 additions & 1 deletion src/lib/md-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import { Docs } from './md-docs';
import { rehypePlugins, remarkPlugins } from './md-plugins';
import { rehypeExtractHeadings } from './plugins/toc';

const isPreview = process.env.VERCEL_ENV === 'preview';
const branchUrl = `https://${process.env.VERCEL_BRANCH_URL}/`;

const docConfigPath = join(DOCS_DIRECTORY, '../src/config/docs.json');
const configFile = JSON.parse(readFileSync(docConfigPath, 'utf8'));
const BASE_URL = 'https://docs.fuel.network/';
const BASE_URL =
isPreview && branchUrl ? branchUrl : 'https://docs.fuel.network/';

export class Doc {
md: MdDoc;
Expand Down
Loading

0 comments on commit c686cbc

Please sign in to comment.