-
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.
Merge pull request #86 from holidayextras/redirects
Add ability to write redirects for Paultons
- Loading branch information
Showing
3 changed files
with
30 additions
and
1 deletion.
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
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,22 @@ | ||
import fs from 'fs' | ||
|
||
const writeRedirect = (documentData) => { | ||
// Prismic custom field with redirect value | ||
const redirectValue = documentData?.redirect?.json?.value | ||
// Prismic custom field for slug or UID which every document has by default | ||
const pageUrl = documentData?.slug?.json?.value || documentData.uid | ||
if (!redirectValue || !pageUrl || !redirectValue.includes('https://')) return | ||
|
||
try { | ||
const redirectCommand = ` | ||
aws s3 cp s3://$BUCKET/${pageUrl}.html s3://$BUCKET/${pageUrl}.html --website-redirect ${redirectValue} | ||
aws s3 cp s3://$BUCKET/${pageUrl} s3://$BUCKET/${pageUrl} --website-redirect ${redirectValue}` | ||
if (!fs.existsSync('./bin')) fs.mkdirSync('./bin') | ||
fs.appendFileSync('./bin/redirects.sh', redirectCommand, { mode: 0o755 }) | ||
console.log(`Added redirect for ${pageUrl} to ${redirectValue}`) | ||
} catch (err) { | ||
console.log(`Writing redirect to bash file for ${pageUrl} has failed.`, err) | ||
} | ||
} | ||
|
||
export default writeRedirect |