Skip to content

Commit

Permalink
Merge pull request #2799 from focusreactive/fr/hotfix/relative-links
Browse files Browse the repository at this point in the history
Fr/hotfix/relative links
  • Loading branch information
fvictorio authored Jun 8, 2022
2 parents ebde426 + 84cd816 commit 17b8a23
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 34 deletions.
56 changes: 47 additions & 9 deletions docs/src/components/mdxComponents/MDLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactElement } from "react";
import { styled } from "linaria/react";
import Link from "next/link";
import { useRouter } from "next/router";
import { media, tm, tmDark, tmHCDark, tmSelectors } from "../../themes";
import ExternalLinkIcon from "../../assets/icons/external-link-icon";

Expand Down Expand Up @@ -64,22 +65,42 @@ const StyledMdLinkContainer = styled.span`
}
`;

const getPathFromHref = (href: string) => {
const pathname = href
const getAbsoluteHrefFromRelativePath = (href: string, currentHref: string) => {
const pathSegments = currentHref
.split("/")
.filter((hrefPart: string) => ![".", ".."].includes(hrefPart))
.join("/")
.toLowerCase();
.filter((segment) => segment !== "");
const hrefSegments = href.split("/").filter((segment) => segment !== ".");

return pathname.startsWith("/") ? pathname : `/${pathname}`;
const pathSegmentsCount = pathSegments.length;
const upperLevelsCount = hrefSegments.filter(
(segment) => segment === ".."
).length;

const baseSegmentsCount = Math.max(
pathSegmentsCount - 1 - upperLevelsCount,
0
);

const baseSegments = pathSegments.slice(0, baseSegmentsCount + 1);

const newSegments = ["", ...baseSegments, ...hrefSegments];

return newSegments.join("/").replace("/index", "");
};

const renderLinkByType = ({
children,
href,
isExternalLink,
isAnchor,
}: Props & { isExternalLink: boolean; isAnchor: boolean }) => {
isAbsoluteLink,
currentHref,
}: Props & {
isExternalLink: boolean;
isAnchor: boolean;
isAbsoluteLink: boolean;
currentHref: string;
}) => {
if (isExternalLink) {
return (
<a href={href} target="_blank" rel="noreferrer">
Expand All @@ -91,22 +112,39 @@ const renderLinkByType = ({
if (isAnchor) {
return <a href={href}>{children}</a>;
}
if (isAbsoluteLink) {
return (
<Link href={href}>
{/* eslint-disable-next-line */}
<a>{children}</a>
</Link>
);
}

return (
<Link href={getPathFromHref(href.replace(/\.md$/, ""))}>
<Link href={getAbsoluteHrefFromRelativePath(href, currentHref)}>
{/* eslint-disable-next-line */}
<a>{children}</a>
</Link>
);
};

const MDLink = ({ children, href }: Props) => {
const router = useRouter();
const isExternalLink = href.startsWith("http");
const isAbsoluteLink = href.startsWith("/");
const isAnchor = href.startsWith("#");

return (
<StyledMdLinkContainer>
{renderLinkByType({ href, children, isAnchor, isExternalLink })}
{renderLinkByType({
href: href.replace(/\.mdx?$/, ""),
children,
isAnchor,
isExternalLink,
isAbsoluteLink,
currentHref: router.asPath,
})}
</StyledMdLinkContainer>
);
};
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/chai-matchers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ expect("0x00012AB").to.hexEqual("0x12ab");

## Dig Deeper

For a full listing of all of the matchers supported by this package, see [the reference documentation](/chai-matchers/reference).
For a full listing of all of the matchers supported by this package, see [the reference documentation](./reference.md).
2 changes: 1 addition & 1 deletion docs/src/content/chai-matchers/migrate-from-waffle.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ The `@nomicfoundation/hardhat-chai-matchers` plugin is meant to be a drop-in rep

The Hardhat Chai Matchers are compatible with Waffle's API and offer several advantages:

- **More features**: the Hardhat Chai Matchers include new matchers, like [`.revertedWithCustomError`](/chai-matchers/reference#.revertedwithcustomerror) and [`.revertedWithPanic`](/chai-matchers/reference#.revertedwithpanic), which let you perform better assertions of a transaction's revert reason.
- **More features**: the Hardhat Chai Matchers include new matchers, like [`.revertedWithCustomError`](/chai-matchers/reference#.revertedwithcustomerror) and [`.revertedWithPanic`](/chai-matchers/reference.md#.revertedwithpanic), which let you perform better assertions of a transaction's revert reason.
- **Support for native BigInts**: Besides numbers and ethers’s BigNumbers, you can also use JavaScript's native BigInts in your assertions, which means being able to do things like `expect(await token.totalSupply()).to.equal(10n**18n)` instead of `expect(await token.totalSupply()).to.equal(ethers.BigNumber.from("1000000000000000000"))`.
- **More reliable**: Several problems and minor bugs in Waffle's matchers are fixed in the Hardhat Chai Matchers.
4 changes: 2 additions & 2 deletions docs/src/content/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ You can customize which network is used by default when running Hardhat by setti

### Hardhat Network

Hardhat comes built-in with a special network called `hardhat`. When using this network, an instance of the [Hardhat Network](../hardhat-network/README.md) will be automatically created when you run a task, script or test your smart contracts.
Hardhat comes built-in with a special network called `hardhat`. When using this network, an instance of the [Hardhat Network](../hardhat-network/index.md) will be automatically created when you run a task, script or test your smart contracts.

Hardhat Network has first-class support of Solidity. It always knows which smart contracts are being run and exactly what they do and why they fail. Learn more about it [here](../hardhat-network/README.md).
Hardhat Network has first-class support of Solidity. It always knows which smart contracts are being run and exactly what they do and why they fail. Learn more about it [here](../hardhat-network/index.md).

See [the Hardhat Network Configuration Reference](../hardhat-network/reference/#config) for details on what can be configured.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/guides/compile-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Compiling...
Compiled 1 contract successfully
```

The compiled artifacts will be saved in the `artifacts/` directory by default, or whatever your configured artifacts path is. Look at the [paths configuration section](../config/README.md#path-configuration) to learn how to change it. This directory will be created if it doesn't exist.
The compiled artifacts will be saved in the `artifacts/` directory by default, or whatever your configured artifacts path is. Look at the [paths configuration section](../config/index.md#path-configuration) to learn how to change it. This directory will be created if it doesn't exist.

After the initial compilation, Hardhat will try to do the least amount of work possible the next time you compile. For example, if you didn't change any files since the last compilation, nothing will be compiled:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/guides/create-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ For our example, we will use Web3.js to interact with our contracts, so we will
npm install --save-dev @nomiclabs/hardhat-web3 web3
```

(Take a look at the [list of Hardhat plugins](../plugins/README.md) to see other available libraries.)
(Take a look at the [list of Hardhat plugins](../plugins/index.md) to see other available libraries.)

Task creation code can go in `hardhat.config.js`, or whatever your configuration file is called. It’s a good place to create simple tasks. If your task is more complex, it's also perfectly valid to split the code into several files and `require` them from the configuration file.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/guides/ganache-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Running tests with Ganache

Rather than using Ganache, we recommend using the built-in [Hardhat Network](../hardhat-network/README.md) network to test your smart contracts, as it generates [combined JavaScript and Solidity stack traces](../hardhat-network/README.md#solidity-stack-traces), making debugging easier.
Rather than using Ganache, we recommend using the built-in [Hardhat Network](../hardhat-network/index.md) network to test your smart contracts, as it generates [combined JavaScript and Solidity stack traces](../hardhat-network/index.md#solidity-stack-traces), making debugging easier.

If you still want to run your tests using Ganache, you can do it in two ways.

Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/guides/project-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ These are the default paths for a Hardhat project.
- `test/` is where your tests should go.
- `scripts/` is where simple automation scripts go.

If you need to change these paths, take a look at the [paths configuration section](../config/README.md#path-configuration).
If you need to change these paths, take a look at the [paths configuration section](../config/index.md#path-configuration).

### Testing and Ethereum networks

When it comes to testing your contracts, Hardhat comes with some built-in defaults:

- The built-in [Hardhat Network](../hardhat-network/README.md) as the development network to test on
- The built-in [Hardhat Network](../hardhat-network/index.md) as the development network to test on
- [Mocha](https://mochajs.org/) as the test runner

If you need to use an external network, like an Ethereum testnet, mainnet or some other specific node software, you can set it up using the `networks` configuration entries in the exported object in `hardhat.config.js`, which is how Hardhat projects manage settings.

You can use of the `--network` CLI parameter to quickly change the network.

Take a look at the [networks configuration section](../config/README.md#networks-configuration) to learn more about setting up different networks.
Take a look at the [networks configuration section](../config/index.md#networks-configuration) to learn more about setting up different networks.

### Plugins and dependencies

Expand All @@ -85,7 +85,7 @@ You need to install these dependencies to run the sample project:
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
```

This stems from the fact that **most of Hardhat's functionality comes from plugins**, so check out the [plugins section](../plugins/README.md) for the official list and see if there are any other ones of interest to you.
This stems from the fact that **most of Hardhat's functionality comes from plugins**, so check out the [plugins section](../plugins/index.md) for the official list and see if there are any other ones of interest to you.

The sample project uses the `@nomiclabs/hardhat-waffle` plugin, which depends on the `@nomiclabs/hardhat-ethers` plugin. These integrate the Ethers.js and Waffle tools into your project.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/guides/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ You can still pass arguments to Hardhat when using it as a library. This is done
- `HARDHAT_MAX_MEMORY`: Sets the maximum amount of memory that Hardhat can use.

[hardhat runtime environment]: ../advanced/hardhat-runtime-environment.md
[getting started guide]: ../getting-started/README.md
[getting started guide]: ../getting-started/index.md
4 changes: 2 additions & 2 deletions docs/src/content/guides/waffle-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Ethers and Waffle support TypeScript. Learn how to set up Hardhat with TypeScrip

## Setting up

[Install Hardhat](/getting-started/README.md#installation) on an empty directory. When done, run `npx hardhat`.
[Install Hardhat](/getting-started/index.md#installation) on an empty directory. When done, run `npx hardhat`.

```
$ npx hardhat
Expand Down Expand Up @@ -255,5 +255,5 @@ const provider = waffle.provider;

Run your tests with `npx hardhat test` and you should get stack traces when a transaction fails.

[hardhat network]: ../hardhat-network/README.md
[hardhat network]: ../hardhat-network/index.md
[hardhat runtime environment]: ../advanced/hardhat-runtime-environment.md
4 changes: 2 additions & 2 deletions docs/src/content/hardhat-network/explanation/mining-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Hardhat Network can be configured to **automine** blocks, immediately upon recei

You can use one of these modes, both or neither. By default, only the automine mode is enabled.

When automine is disabled, every sent transaction is added to the mempool, which contains all the transactions that could be mined in the future. By default, Hardhat Network's mempool follows the same rules as Geth. This means, among other things, that transactions are prioritized by fees paid to the miner (and then by arrival time), and that invalid transactions are dropped. In addition to the default mempool behavior, an [alternative FIFO behavior is also available](../reference/README.md#transaction-ordering).
When automine is disabled, every sent transaction is added to the mempool, which contains all the transactions that could be mined in the future. By default, Hardhat Network's mempool follows the same rules as Geth. This means, among other things, that transactions are prioritized by fees paid to the miner (and then by arrival time), and that invalid transactions are dropped. In addition to the default mempool behavior, an [alternative FIFO behavior is also available](../reference/index.md#transaction-ordering).

When automine is disabled, pending transactions can be queried via the `eth_getBlockByNumber` RPC method (with `"pending"` as the block number argument), they can be removed using the `hardhat_dropTransaction` RPC method, and they can be replaced by submitting a new transaction with the same nonce but with a 10+% increase in fees paid to the miner.

Expand Down Expand Up @@ -58,7 +58,7 @@ You can also replace a transaction by sending a new one with the same nonce as t

## Configuring Mining Modes

See [the Mining Modes configuration reference](../reference/README.md#mining-modes) to understand what to put in your Hardhat config file.
See [the Mining Modes configuration reference](../reference/index.md#mining-modes) to understand what to put in your Hardhat config file.

### Using RPC methods

Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/hardhat-network/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ To use it, you simply import `hardhat/console.sol` and call it. It implements th

It always works, regardless of the call or transaction failing or being successful. And, because it's implemented in standard Solidity, it works with _any_ tool or library, emitting log entries where it's fully supported &mdash; Hardhat Network, Remix, and Tenderly &mdash; and falling back gracefully to a no-op everywhere else &mdash; Remix, Waffle, Truffle, etc &mdash; though it does consume a small amount of gas on live networks.

You can see an example in the Sample Project. Follow the steps in [Quick Start](/getting-started/README.md#quick-start) to try it out. You can also refer to more details in [the reference documentation](./reference/README.md#console-log).
You can see an example in the Sample Project. Follow the steps in [Quick Start](/getting-started/index.md#quick-start) to try it out. You can also refer to more details in [the reference documentation](./reference/index.md#console-log).

### Mainnet forking

Expand Down Expand Up @@ -159,16 +159,16 @@ eth_call
at process._tickCallback (internal/process/next_tick.js:68:7)
```

This logging is enabled by default when using Hardhat Network's node (i.e. `npx hardhat node`), but disabled when using the in-process Hardhat Network provider. See [Hardhat Network's config](../config/README.md#hardhat-network) to learn more about how to control its logging.
This logging is enabled by default when using Hardhat Network's node (i.e. `npx hardhat node`), but disabled when using the in-process Hardhat Network provider. See [Hardhat Network's config](../config/index.md#hardhat-network) to learn more about how to control its logging.

### The `debug_traceTransaction` method

You can get debug traces of already-mined transactions using the `debug_traceTransaction` RPC method. The returned object has a detailed description of the transaction execution, including a list of steps describing each executed opcode and the state of the EVM at that point.

If you are using [mainnet forking](guides/mainnet-forking.html) with an archive node, you can get traces of transactions from the remote network even if the node you are using doesn't support `debug_traceTransaction`.

For more details, see [the reference documentation for this method](./reference/README.md#debug-tracetransaction).
For more details, see [the reference documentation for this method](./reference/index.md#debug-tracetransaction).

## Dig deeper

This has been just a high-level explanation of what Hardhat Network is. To dig deeper, see [the Reference documentation](./reference/README.md). <!-- TODO: when they exist, add additional links here to "Guides", "Tutorials" and "Explanations" of more specific things. -->
This has been just a high-level explanation of what Hardhat Network is. To dig deeper, see [the Reference documentation](./reference/index.md). <!-- TODO: when they exist, add additional links here to "Guides", "Tutorials" and "Explanations" of more specific things. -->
6 changes: 3 additions & 3 deletions docs/src/content/hardhat-network/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ This setting changes how Hardhat Network works, to mimic Ethereum's mainnet at a

#### `throwOnTransactionFailures`

A boolean that controls if Hardhat Network throws on transaction failures. If this value is `true`, Hardhat Network will throw [combined JavaScript and Solidity stack traces](../README.md#solidity-stack-traces) on transaction failures. If it is `false`, it will return the failing transaction hash. In both cases the transactions are added into the blockchain. Default value: `true`
A boolean that controls if Hardhat Network throws on transaction failures. If this value is `true`, Hardhat Network will throw [combined JavaScript and Solidity stack traces](../index.md#solidity-stack-traces) on transaction failures. If it is `false`, it will return the failing transaction hash. In both cases the transactions are added into the blockchain. Default value: `true`

#### `throwOnCallFailures`

A boolean that controls if Hardhat Network throws on call failures. If this value is `true`, Hardhat Network will throw [combined JavaScript and Solidity stack traces](../README.md#solidity-stack-traces) when a call fails. If it is `false`, it will return the call's `return data`, which can contain a revert reason. Default value: `true`
A boolean that controls if Hardhat Network throws on call failures. If this value is `true`, Hardhat Network will throw [combined JavaScript and Solidity stack traces](../index.md#solidity-stack-traces) when a call fails. If it is `false`, it will return the call's `return data`, which can contain a revert reason. Default value: `true`

#### `loggingEnabled`

Expand Down Expand Up @@ -237,7 +237,7 @@ Hardhat Network is initialized by default in this state:
- `0xdD2FD4581271e230360230F9337D5c0430Bf44C0`
- `0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199`

To customise it, take a look at [the configuration section](/config/README.md#hardhat-network).
To customise it, take a look at [the configuration section](/config/index.md#hardhat-network).

## JSON-RPC methods support

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Trying to send 100 tokens to 0xe5904695748fe4a84b40b3fc79de2277660bd1d3
5 passing (2s)
```

Check out the [documentation](/hardhat-network/README.md#console-log) to learn more about this feature.
Check out the [documentation](/hardhat-network/index.md#console-log) to learn more about this feature.
2 changes: 1 addition & 1 deletion packages/hardhat-solhint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ There are no additional steps you need to take for this plugin to work.

Install it, run `npx hardhat check` and check the Solhint report.

You may want to add a [solhint configuration](https://github.com/protofire/solhint/blob/master/README.md) file to customize your rules or include a Solhint plugin.
You may want to add a [solhint configuration](https://github.com/protofire/solhint/blob/master) file to customize your rules or include a Solhint plugin.

1 comment on commit 17b8a23

@vercel
Copy link

@vercel vercel bot commented on 17b8a23 Jun 8, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.