forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added local plugin to fix windows error (nodejs#2773)
* added local plugin to fix windows error * updated package.json for local plugin * added readme and set the plugin package.json to private
- Loading branch information
1 parent
2cfa1b7
commit 328e0e2
Showing
8 changed files
with
92 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Get Chalk | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This plugin is a replacement for the unmaintained `gatsby-plugin-meta-redirect`. The major change I made was removing the fs-extra module from it and using the built-in fs module instead. | ||
|
||
The problem we were running into was the fs-extra module was throwing on an invalid character in our path for windows users. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
/* eslint-disable no-restricted-syntax */ | ||
const path = require('path'); | ||
const fs = require('node:fs/promises'); | ||
|
||
const getMetaRedirect = require('./redirect'); | ||
|
||
async function writeRedirectsFile(redirects, folder, pathPrefix) { | ||
if (!redirects.length) return; | ||
|
||
for (const redirect of redirects) { | ||
const { fromPath, toPath } = redirect; | ||
|
||
const FILE_PATH = path.join( | ||
folder, | ||
fromPath.replace(pathPrefix, ''), | ||
'index.html' | ||
); | ||
|
||
try { | ||
const data = getMetaRedirect(toPath); | ||
await fs.writeFile(FILE_PATH, data); | ||
} catch (_) { | ||
// nothing to see here.... | ||
} | ||
} | ||
} | ||
|
||
exports.onPostBuild = ({ store }) => { | ||
const { redirects, program, config } = store.getState(); | ||
|
||
let pathPrefix = ''; | ||
if (program.prefixPaths) { | ||
pathPrefix = config.pathPrefix; | ||
} | ||
|
||
const folder = path.join(program.directory, 'public'); | ||
return writeRedirectsFile(redirects, folder, pathPrefix); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "gatsby-plugin-meta-redirect", | ||
"version": "1.1.1", | ||
"author": "Danny Wilson <dwilson@getchalk.com>", | ||
"license": "MIT", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function redirect(toPath) { | ||
let url = toPath.trim(); | ||
|
||
const hasProtocol = url.includes('://'); | ||
if (!hasProtocol) { | ||
const hasLeadingSlash = url.startsWith('/'); | ||
if (!hasLeadingSlash) { | ||
url = `/${url}`; | ||
} | ||
|
||
const resemblesFile = url.includes('.'); | ||
if (!resemblesFile) { | ||
url = `${url}/`.replace(/\/\/+/g, '/'); | ||
} | ||
} | ||
|
||
return `<meta http-equiv="refresh" content="0; URL='${url}'" />`; | ||
}; |