Skip to content

Commit

Permalink
WIP tryna get redirects working
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr committed Oct 7, 2022
1 parent f8fea0d commit 42d8989
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
siteUrl: 'https://almost-dead.net',
},
plugins: [
'gatsby-plugin-meta-redirect',
{
resolve: `gatsby-source-filesystem`,
options: {
Expand Down
17 changes: 13 additions & 4 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const ShowEmbedTemplate = require.resolve('./src/templates/show-embed.js')
const SongTemplate = require.resolve('./src/templates/song.js')
const VenueTemplate = require.resolve('./src/templates/venue.js')

function urlify(string) {
return slugify(string, {remove: /[^a-z\d ]/gi})
}

exports.createSchemaCustomization = ({actions: {createTypes}}) => {
// n.b. this is GraphQL "SDL"
createTypes(`
Expand Down Expand Up @@ -77,7 +81,7 @@ exports.createSchemaCustomization = ({actions: {createTypes}}) => {
`)
}

exports.createPages = async ({graphql, actions: {createPage, createTypes} }) => {
exports.createPages = async ({graphql, actions: {createPage, createRedirect} }) => {
const result = await graphql(`
query Everything {
allVenuesCsv {
Expand Down Expand Up @@ -150,13 +154,18 @@ exports.createPages = async ({graphql, actions: {createPage, createTypes} }) =>
})

songs.filter(song => song.title && song.title !== '[unknown]').forEach((song) => {
const songPageUrl = `/song/${song.id}-${urlify(song.title)}`
createRedirect({
fromPath: `/song/${song.id}`,
toPath: songPageUrl,
})
createPage({
path: `/song/${song.id}`,
path: songPageUrl,
component: SongTemplate,
context: {
songId: song.id,
}
})
},
});
})

venues.filter(venue => venue.name).forEach(venue => {
Expand Down
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"gatsby-plugin-google-fonts": "^1.0.1",
"gatsby-plugin-image": "^1.11.0",
"gatsby-plugin-loadable-components-ssr": "^4.3.2",
"gatsby-plugin-meta-redirect": "^1.1.1",
"gatsby-plugin-react-helmet": "^4.14.0",
"gatsby-source-filesystem": "^3.14.0",
"gatsby-transformer-csv": "^3.14.0",
Expand Down
4 changes: 2 additions & 2 deletions src/templates/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function SortableTable({columns, data, previousUrl=''}) {
prepareRow(row) // no return value; mutates `row`?
return <tr {...row.getRowProps()}>
{row.cells.map(cell => {
const url = `/show/${cell.row.original.fullData.showData.id}`
// const url = `/show/${cell.row.original.fullData.showData.id}`
const classNameTd = classnames({
blank: cell.value === '[opener]' || cell.value === '[closer]',
[`sortable__cell-${cell.column.id}`]: true,
Expand Down Expand Up @@ -213,7 +213,7 @@ export default function Song({data: {
after.segue = find(propEq('from_perf_id', performanceIdStr))(allSegues)?.type || ','
} else after = {song_name: '[closer]'}
const whichSet = Object.entries(SET_MAPPING)
.find(([col_name, readable_name]) => showData[col_name] === setData.id)[1]
.find(([col_name, _readable_name]) => showData[col_name] === setData.id)[1]
const variation = performanceData.variation
? `(${performanceData.variation})`
: false
Expand Down

0 comments on commit 42d8989

Please sign in to comment.