File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @holidayextras/static-site-generator" ,
3- "version" : " 9.1.1 " ,
3+ "version" : " 9.2.0 " ,
44 "description" : " Holiday Extras Static Site Generator in metalsmith / react" ,
55 "repository" : {
66 "type" : " git" ,
Original file line number Diff line number Diff line change 11import prismic from './metalsmith-prismic'
22import hxseo from './getHXSEOContent'
3+ import writeRedirect from './writeRedirect'
34import apiCaller from './apiCaller'
45import _ from 'lodash'
56
@@ -16,12 +17,18 @@ const getDataSource = (opts) => {
1617 accessToken : opts . dataSource . accessToken ,
1718 linkResolver : configLinkResolver || function ( ctx , doc ) {
1819 if ( doc . isBroken ) return ''
20+
21+ // create redirect script if needed
22+ writeRedirect ( doc . data )
23+
24+ // Page url
1925 if ( _ . has ( doc , 'data.slug.json.value' ) ) {
2026 const regExpDomain = new RegExp ( `.*${ opts . config . domainSettings . domainLive } ` )
2127 // Strip domain (+ everything before it) off of the slug in case it was added by mistake
2228 const slug = doc . data . slug . json . value
2329 return slug . replace ( regExpDomain , '' )
2430 }
31+
2532 return '/' + doc . uid
2633 }
2734 } )
Original file line number Diff line number Diff line change 1+ import fs from 'fs'
2+
3+ const writeRedirect = ( documentData ) => {
4+ // Prismic custom field with redirect value
5+ const redirectValue = documentData ?. redirect ?. json ?. value
6+ // Prismic custom field for slug or UID which every document has by default
7+ const pageUrl = documentData ?. slug ?. json ?. value || documentData . uid
8+ if ( ! redirectValue || ! pageUrl || ! redirectValue . includes ( 'https://' ) ) return
9+
10+ try {
11+ const redirectCommand = `
12+ aws s3 cp s3://$BUCKET/${ pageUrl } .html s3://$BUCKET/${ pageUrl } .html --website-redirect ${ redirectValue }
13+ aws s3 cp s3://$BUCKET/${ pageUrl } s3://$BUCKET/${ pageUrl } --website-redirect ${ redirectValue } `
14+ if ( ! fs . existsSync ( './bin' ) ) fs . mkdirSync ( './bin' )
15+ fs . appendFileSync ( './bin/redirects.sh' , redirectCommand , { mode : 0o755 } )
16+ console . log ( `Added redirect for ${ pageUrl } to ${ redirectValue } ` )
17+ } catch ( err ) {
18+ console . log ( `Writing redirect to bash file for ${ pageUrl } has failed.` , err )
19+ }
20+ }
21+
22+ export default writeRedirect
You can’t perform that action at this time.
0 commit comments