Skip to content

Commit cb43817

Browse files
authored
feat: add remark plugin to rewrite localized links in Markdown content
1 parent e8dbc45 commit cb43817

5 files changed

Lines changed: 697 additions & 42 deletions

File tree

astro/astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import { defineConfig } from 'astro/config';
33
import mdx from '@astrojs/mdx';
44
import icon from 'astro-icon';
5+
import remarkRewriteLocalizedLinks from './src/utils/remark/rewrite-localized-links.mjs';
56

67
// https://astro.build/config
78
export default defineConfig({
89
integrations: [mdx(), icon()],
910
markdown: {
11+
remarkPlugins: [[remarkRewriteLocalizedLinks, { prefixes: ['guide', 'starter', 'api'] }]],
1012
shikiConfig: {
1113
theme: 'github-dark',
1214
},

astro/src/content/docs/en/4x/guide/routing.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ description: Learn how to define and use routes in Express.js applications, incl
66
# Routing
77

88
_Routing_ refers to how an application's endpoints (URIs) respond to client requests.
9-
For an introduction to routing, see [Basic routing](/{{ page.lang }}/starter/basic-routing.html).
9+
For an introduction to routing, see [Basic routing](/starter/basic-routing.html).
1010

1111
You define routing using methods of the Express `app` object that correspond to HTTP methods;
1212
for example, `app.get()` to handle GET requests and `app.post` to handle POST requests. For a full list,
13-
see [app.METHOD](/{{ page.lang }}/5x/api.html#app.METHOD). You can also use [app.all()](/{{ page.lang }}/5x/api.html#app.all) to handle all HTTP methods and [app.use()](/{{ page.lang }}/5x/api.html#app.use) to
14-
specify middleware as the callback function (See [Using middleware](/{{ page.lang }}/guide/using-middleware.html) for details).
13+
see [app.METHOD](/api/application/app-METHOD). You can also use [app.all()](/api/application/app-all) to handle all HTTP methods and [app.use()](/api/application/app-use) to
14+
specify middleware as the callback function (See [Using middleware](/guide/using-middleware.html) for details).
1515

1616
These routing methods specify a callback function (sometimes called "handler functions") called when the application receives a request to the specified route (endpoint) and HTTP method. In other words, the application "listens" for requests that match the specified route(s) and method(s), and when it detects a match, it calls the specified callback function.
1717

@@ -50,7 +50,7 @@ app.post('/', (req, res) => {
5050
```
5151

5252
Express supports methods that correspond to all HTTP request methods: `get`, `post`, and so on.
53-
For a full list, see [app.METHOD](/{{ page.lang }}/5x/api.html#app.METHOD).
53+
For a full list, see [app.METHOD](/api/application/app-METHOD).
5454

5555
There is a special routing method, `app.all()`, used to load middleware functions at a path for _all_ HTTP request methods. For example, the following handler is executed for requests to the route `"/secret"` whether using `GET`, `POST`, `PUT`, `DELETE`, or any other HTTP request method supported in the [http module](https://nodejs.org/api/http.html#http_http_methods).
5656

@@ -65,7 +65,7 @@ app.all('/secret', (req, res, next) => {
6565

6666
Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions.
6767

68-
{% capture caution-character %} In express 5, the characters `?`, `+`, `*`, `[]`, and `()` are handled differently than in version 4, please review the [migration guide](/{{ page.lang }}/guide/migrating-5.html#path-syntax) for more information.{% endcapture %}
68+
{% capture caution-character %} In express 5, the characters `?`, `+`, `*`, `[]`, and `()` are handled differently than in version 4, please review the [migration guide](/guide/migrating-5.html#path-syntax) for more information.{% endcapture %}
6969

7070
{% include admonitions/caution.html content=caution-character %}
7171

@@ -118,7 +118,7 @@ app.get('/random.text', (req, res) => {
118118

119119
### Route paths based on string patterns
120120

121-
{% capture caution-string-patterns %} The string patterns in Express 5 no longer work. Please refer to the [migration guide](/{{ page.lang }}/guide/migrating-5.html#path-syntax) for more information.{% endcapture %}
121+
{% capture caution-string-patterns %} The string patterns in Express 5 no longer work. Please refer to the [migration guide](/guide/migrating-5.html#path-syntax) for more information.{% endcapture %}
122122

123123
{% include admonitions/caution.html content=caution-string-patterns %}
124124

@@ -209,7 +209,7 @@ req.params: { "genus": "Prunus", "species": "persica" }
209209
```
210210

211211
{% capture warning-regexp %}
212-
In express 5, Regexp characters are not supported in route paths, for more information please refer to the [migration guide](/{{ page.lang }}/guide/migrating-5.html#path-syntax).{% endcapture %}
212+
In express 5, Regexp characters are not supported in route paths, for more information please refer to the [migration guide](/guide/migrating-5.html#path-syntax).{% endcapture %}
213213

214214
{% include admonitions/caution.html content=warning-regexp %}
215215

@@ -239,7 +239,7 @@ In Express 4.x, <a href="https://github.com/expressjs/express/issues/2495">the `
239239

240240
<h2 id="route-handlers">Route handlers</h2>
241241

242-
You can provide multiple callback functions that behave like [middleware](/{{ page.lang }}/guide/using-middleware.html) to handle a request. The only exception is that these callbacks might invoke `next('route')` to bypass the remaining route callbacks. You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there's no reason to proceed with the current route.
242+
You can provide multiple callback functions that behave like [middleware](/guide/using-middleware.html) to handle a request. The only exception is that these callbacks might invoke `next('route')` to bypass the remaining route callbacks. You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there's no reason to proceed with the current route.
243243

244244
```js
245245
app.get('/user/:id', (req, res, next) => {
@@ -334,22 +334,22 @@ app.get(
334334

335335
The methods on the response object (`res`) in the following table can send a response to the client, and terminate the request-response cycle. If none of these methods are called from a route handler, the client request will be left hanging.
336336

337-
| Method | Description |
338-
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
339-
| [res.download()](/{{ page.lang }}/5x/api.html#res.download) | Prompt a file to be downloaded. |
340-
| [res.end()](/{{ page.lang }}/5x/api.html#res.end) | End the response process. |
341-
| [res.json()](/{{ page.lang }}/5x/api.html#res.json) | Send a JSON response. |
342-
| [res.jsonp()](/{{ page.lang }}/5x/api.html#res.jsonp) | Send a JSON response with JSONP support. |
343-
| [res.redirect()](/{{ page.lang }}/5x/api.html#res.redirect) | Redirect a request. |
344-
| [res.render()](/{{ page.lang }}/5x/api.html#res.render) | Render a view template. |
345-
| [res.send()](/{{ page.lang }}/5x/api.html#res.send) | Send a response of various types. |
346-
| [res.sendFile()](/{{ page.lang }}/5x/api.html#res.sendFile) | Send a file as an octet stream. |
347-
| [res.sendStatus()](/{{ page.lang }}/5x/api.html#res.sendStatus) | Set the response status code and send its string representation as the response body. |
337+
| Method | Description |
338+
| ------------------------------------------------ | ------------------------------------------------------------------------------------- |
339+
| [res.download()](/api/response/res-download) | Prompt a file to be downloaded. |
340+
| [res.end()](/api/response/res-end) | End the response process. |
341+
| [res.json()](/api/response/res-json) | Send a JSON response. |
342+
| [res.jsonp()](/api/response/res-jsonp) | Send a JSON response with JSONP support. |
343+
| [res.redirect()](/api/response/res-redirect) | Redirect a request. |
344+
| [res.render()](/api/response/res-render) | Render a view template. |
345+
| [res.send()](/api/response/res-send) | Send a response of various types. |
346+
| [res.sendFile()](/api/response/res-sendfile) | Send a file as an octet stream. |
347+
| [res.sendStatus()](/api/response/res-sendstatus) | Set the response status code and send its string representation as the response body. |
348348

349349
<h2 id="app-route">app.route()</h2>
350350

351351
You can create chainable route handlers for a route path by using `app.route()`.
352-
Because the path is specified at a single location, creating modular routes is helpful, as is reducing redundancy and typos. For more information about routes, see: [Router() documentation](/{{ page.lang }}/5x/api.html#router).
352+
Because the path is specified at a single location, creating modular routes is helpful, as is reducing redundancy and typos. For more information about routes, see: [Router() documentation](/api.html#router).
353353

354354
Here is an example of chained route handlers that are defined by using `app.route()`.
355355

@@ -410,7 +410,7 @@ app.use('/birds', birds);
410410

411411
The app will now be able to handle requests to `/birds` and `/birds/about`, as well as call the `timeLog` middleware function that is specific to the route.
412412

413-
But if the parent route `/birds` has path parameters, it will not be accessible by default from the sub-routes. To make it accessible, you will need to pass the `mergeParams` option to the Router constructor [reference](/{{ page.lang }}/5x/api.html#app.use).
413+
But if the parent route `/birds` has path parameters, it will not be accessible by default from the sub-routes. To make it accessible, you will need to pass the `mergeParams` option to the Router constructor [reference](/api/application/app-use).
414414

415415
```js
416416
const router = express.Router({ mergeParams: true });

0 commit comments

Comments
 (0)