-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js + Vercel! ▲ #1
base: latest
Are you sure you want to change the base?
Changes from all commits
8917b5d
b918444
245e395
2d90607
c9ff0a9
6eba7bb
8775285
eb4b6fd
5d255a3
d903cb0
cd2a576
b2bd31e
97f7432
165e4e3
1b223e4
80dfa76
ba2a0ed
52fef75
cc7b0b9
55bc771
a896926
5de5fb4
5bacb15
8f5bc94
5431714
6128a03
f418e99
0831d7f
7c851d7
cb6b004
ba19ae5
fe51f71
75b33a1
b597af4
9edee97
ba9fe1b
05ba343
71c9f66
c8311b7
1b0a2ea
3c36090
7d80311
c7d1914
2aeb8e4
483c5b9
fe685bf
5441a38
bee1f79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,6 @@ yarn-error.log | |
!.yarn/sdks | ||
!.yarn/versions | ||
secret.env | ||
tsconfig.tsbuildinfo | ||
tsconfig.tsbuildinfo | ||
.next | ||
.vercel |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v12.18.4 | ||
14 | ||
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs/promises'; | ||
import glob from 'glob'; | ||
import { ARTICLE_PAGE, FRONT_PAGE } from '#app/routes/utils/pageTypes'; | ||
import getToggles from '#lib/utilities/getToggles'; | ||
import filterUnknownContentTypes from '#app/routes/utils/sharedDataTransformers/filterUnknownContentTypes'; | ||
import filterEmptyGroupItems from '#app/routes/utils/sharedDataTransformers/filterEmptyGroupItems'; | ||
import squashTopStories from '#app/routes/utils/sharedDataTransformers/squashTopStories'; | ||
import addIdsToGroups from '#app/routes/utils/sharedDataTransformers/addIdsToGroups'; | ||
import filterGroupsWithoutStraplines from '#app/routes/utils/sharedDataTransformers/filterGroupsWithoutStraplines'; | ||
import handleGroupBlocks from '#app/routes/article/handleGroupBlocks'; | ||
import handleEmptyParagraphBlocks from '#app/routes/article/handleEmptyParagraphBlocks'; | ||
import handlePromoData from '#app/routes/article/handlePromoData'; | ||
import addMpuBlock from '#app/routes/article/getInitialData/addMpuBlock'; | ||
import { | ||
augmentWithTimestamp, | ||
addIdsToBlocks, | ||
applyBlockPositioning, | ||
addIndexesToEmbeds, | ||
addNoCookieToEmbeds, | ||
} from '#app/routes/utils/sharedDataTransformers'; | ||
import isListWithLink from '#app/routes/utils/isListWithLink'; | ||
import addIndexToBlockGroups from '#app/routes/utils/sharedDataTransformers/addIndexToBlockGroups'; | ||
|
||
const getLanguageAndDirection = async s => { | ||
const { service } = await import(`#lib/config/services/${s}`); | ||
const { dir, lang } = service.default; | ||
|
||
return { | ||
dir, | ||
lang, | ||
}; | ||
}; | ||
|
||
const getServices = () => | ||
glob | ||
.sync(`./data/**/frontpage/index.json`) | ||
.map(result => result.split('/')[2]); | ||
|
||
const getServicePath = service => path.join(process.cwd(), 'data', service); | ||
|
||
const getMostRead = async service => { | ||
let mostRead = {}; | ||
|
||
const servicePath = getServicePath(service); | ||
const mostReadPath = path.join(servicePath, 'mostRead', 'index.json'); | ||
|
||
try { | ||
mostRead = JSON.parse(await fs.readFile(mostReadPath, 'utf-8')); | ||
} catch {} | ||
|
||
return mostRead; | ||
}; | ||
|
||
const getFrontPageProps = async service => { | ||
const servicePath = getServicePath(service); | ||
const pageDataPath = path.join(servicePath, 'frontpage', 'index.json'); | ||
|
||
let pageData = {}; | ||
|
||
try { | ||
pageData = JSON.parse(await fs.readFile(pageDataPath, 'utf-8')); | ||
pageData = filterUnknownContentTypes(pageData); | ||
pageData = filterEmptyGroupItems(pageData); | ||
pageData = addIdsToGroups(pageData); | ||
pageData = squashTopStories(pageData); | ||
pageData = filterGroupsWithoutStraplines(pageData); | ||
} catch { | ||
return { | ||
pageType: FRONT_PAGE, | ||
service, | ||
statusCode: 404, | ||
}; | ||
} | ||
|
||
const mostRead = await getMostRead(service); | ||
const toggles = await getToggles(service); | ||
const { dir, lang } = await getLanguageAndDirection(service); | ||
|
||
return { | ||
dir, | ||
lang, | ||
pageData, | ||
pageType: FRONT_PAGE, | ||
mostRead, | ||
service, | ||
statusCode: 200, | ||
toggles, | ||
}; | ||
}; | ||
|
||
const getArticlePageProps = async (service, articleId) => { | ||
const servicePath = getServicePath(service); | ||
const pageDataPath = path.join(servicePath, 'articles', `${articleId}.json`); | ||
|
||
let pageData = {}; | ||
|
||
try { | ||
pageData = JSON.parse(await fs.readFile(pageDataPath, 'utf-8')); | ||
pageData = handleGroupBlocks(pageData); | ||
pageData = handleEmptyParagraphBlocks(pageData); | ||
pageData = handlePromoData(pageData); | ||
pageData = augmentWithTimestamp(pageData); | ||
pageData = addMpuBlock(pageData); | ||
pageData = addNoCookieToEmbeds(pageData); | ||
pageData = addIdsToBlocks(pageData); | ||
pageData = applyBlockPositioning(pageData); | ||
pageData = addIndexesToEmbeds(pageData); | ||
pageData = addIndexToBlockGroups(isListWithLink, { | ||
blockGroupType: 'edOjLinks', | ||
})(pageData); | ||
} catch { | ||
return { | ||
pageType: ARTICLE_PAGE, | ||
service, | ||
statusCode: 404, | ||
}; | ||
} | ||
|
||
let secondaryColumn = {}; | ||
|
||
try { | ||
const secondaryColumnPath = path.join( | ||
servicePath, | ||
'secondaryColumn', | ||
'index.json', | ||
); | ||
|
||
secondaryColumn = JSON.parse( | ||
await fs.readFile(secondaryColumnPath, 'utf-8'), | ||
); | ||
} catch {} | ||
|
||
const mostRead = await getMostRead(service); | ||
const toggles = await getToggles(service); | ||
const { dir, lang } = await getLanguageAndDirection(service); | ||
|
||
return { | ||
dir, | ||
lang, | ||
pageData: { | ||
...pageData, | ||
secondaryColumn, | ||
}, | ||
pageType: ARTICLE_PAGE, | ||
mostRead, | ||
service, | ||
statusCode: 200, | ||
toggles, | ||
}; | ||
}; | ||
|
||
export { getArticlePageProps, getFrontPageProps, getServices }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { webpackDirAlias } = require('./dirAlias'); | ||
const MomentTimezoneInclude = require('./src/app/legacy/psammead/moment-timezone-include/src'); | ||
|
||
module.exports = { | ||
reactStrictMode: true, | ||
compiler: { | ||
emotion: true, | ||
}, | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
webpack: config => { | ||
config.resolve.alias = { | ||
...webpackDirAlias, | ||
...config.resolve.alias, | ||
}; | ||
|
||
config.plugins.push( | ||
new MomentTimezoneInclude({ startYear: 2010, endYear: 2025 }), | ||
); | ||
|
||
return config; | ||
}, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we wanted to do as little custom configuration here as possible, but there's a few things going on here that are unavoidable without massive changes to the project.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The move to Next.js didn't require this. Running anything below Node 14 is painful on an M1 Mac, so it was bumped up.