-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Support new content version release in codebase #4441
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
…check after team discussion
This looks great at a glance @corwintines! I still need to review this in depth. Will do so tomorrow... One quick thought since we're using the header ids to compare markdown files - we should ensure we have header ids generated for all our markdown files. i.e. please run this script on all English files: https://github.com/ethereum/ethereum-org-website/blob/dev/src/scripts/generate-heading-ids.js I think ideally we run this as a pre-commit hook on any English file but I'm ok with saving that for a later issue. |
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.
Great work @corwintines. I have added a couple of comments to refactor the code a bit.
gatsby-node.js
Outdated
} | ||
} | ||
} catch { | ||
return true |
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.
I don't like this return that is absorbing all the errors and is different from the return type from the function.
Let the function throw its errors and that the consumer handles what to do with it.
gatsby-node.js
Outdated
exports.onCreateNode = ({ node, getNode, actions }) => { | ||
// Loops through all the files dictated by Gatsby (building pages folder), as well as | ||
// folders flagged through the gatsby-source-filesystem plugin in gatsby-config | ||
// This seems to be where the source and transform holdup is? |
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.
I would suggest removing the comments with questions from the code. I think we can discuss them off record than leaving them there.
And regarding the question, hmm not sure. I think it is more related with the queries execution, when gatsby is preparing to build the pages.
gatsby-node.js
Outdated
return true | ||
} | ||
} | ||
|
||
const outdatedMarkdownPages = [ |
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.
I don't believe outdatedMarkdownPages
are used anymore? ✂️
Co-authored-by: Sam Richards <sbrichards@gmail.com>
gatsby-node.js
Outdated
try { | ||
const splitPath = path.split("/") | ||
splitPath.splice(7, 2) | ||
const englishPath = splitPath.join("/") |
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.
I'm not sure this is right - don't you need to replace the lang (e.g. ar
) with en
in the path?
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.
I think as-is this only drops the /content/translations/
from the path.
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.
I need to parse out without __dirname I think to get this right in hindsight. Will add that in.
gatsby-node.js
Outdated
isContentEnglish: | ||
langVersion < 2 && !page.component.includes("/index.js"), | ||
isContentEnglish, | ||
// // We can check if isContentEnglish through our crawling |
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.
✂️
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.
Also I believe langVersion
is no longer used, so can delete that variable.
General note on this refactor - this now removes the concept of This also means logic that relies on that should be removed/refactored, e.g. any use of Edit: as a result of this we'll also need to rework how we do the |
gatsby-node.js
Outdated
// Add additional context to translated pages | ||
// https://www.gatsbyjs.com/docs/creating-and-modifying-pages/#pass-context-to-pages | ||
exports.onCreatePage = ({ page, actions }) => { | ||
exports.onCreatePage = async ({ page, actions }) => { | ||
const { createPage, deletePage } = actions | ||
|
||
const isTranslated = page.context.language !== defaultLanguage | ||
const hasNoContext = page.context.isOutdated === undefined | ||
const langVersion = getLangContentVersion(page.context.language) |
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.
We're going to need to re-think how we do this, since version is no longer on a language level.
src/pages/developers/tutorials.js
Outdated
? tutorial.lang === pageContext.language | ||
: tutorial.lang === "en" | ||
) | ||
.filter((tutorial) => tutorial.lang === pageContext.language) |
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.
I don't think this logic quite gives us what we want. If a language doesn't have any tutorials, we'll now display 0 tutorials for that language, e.g.
What we want is to:
- if the language has translated tutorials, display those
- if the language doesn't have translated tutorials, display our English tutorials
I feel like we discussed just refactoring the hasTutorials
to be a helper function in this file that iterates through the tutorials & to return true
as soon as it hits one in that native language. If it doesn't find one, return false
. Basically lodash's any
or some
: https://lodash.com/docs/4.17.15#some
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.
(we have lodash installed in the project, so you should be able to use it).
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.
Ah gotcha, my mistake. Will get that added in now!
gatsby-node.js
Outdated
const markdownPath = `${__dirname}/src/content/translations/${lang}/${page}/index.md` | ||
const langHasOutdatedMarkdown = fs.existsSync( | ||
markdownPath, | ||
fs.constants.R_OK | fs.constants.W_OK |
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.
Is this 2nd param needed? What's it do? I notice we don't use it in fs.existsSync
elsewhere.
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.
Probably dont need the W_OK part since we arent writing to it, but just checking if we can read the file. I am using existsSync to check if the file exists is all.
Gatsby Cloud Build Report🚩 Your build failed. See the build logs here |
src/pages/index.js
Outdated
return <LegacyPageHome /> | ||
} | ||
console.log(intl) |
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.
✂️
src/content/developers/tutorials/how-to-use-tellor-as-your-oracle/index.md
Outdated
Show resolved
Hide resolved
FYI @minimalsm I don't think this is actually an issue. The tutorials homepage is a React component, so we don't compare header ids. As long as a language has all the matching keys from the JSON file (https://github.com/ethereum/ethereum-org-website/blob/dev/src/intl/en/page-developers-tutorials.json) it shouldn't display an outdated banner. |
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.
This is looking super close!
Only issues I noticed were some markdown files (seemingly only the developer docs & developer tutorial pages) had wonky header ids (i.e. the header id didn't match the header text). The other markdown pages (e.g. defi & NFTs) seemed to be fine. I suspect because the script to generate the header ids may not work on deep directories?
Maybe we don't worry about refactoring that script but let's update those header ids to be sensible matches (maybe try running it on the specific files?).
.concat(externalTutorials, internalTutorials) | ||
const allTutorials = [].concat(externalTutorials, internalTutorials) | ||
|
||
const hasTutorialsCheck = some(allTutorials, ["lang", pageContext.language]) |
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.
Perhaps more clear as langHasTutorials
?
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.
Looks great! @corwintines good job
@corwintines building it in my local, I see a long list of errors which I don't think adds too much value: should we silence this? or in case we keep it, should we add more details on the error message (e.g. file paths being read)? |
Nice catch @pettinarip
I think the latter - I'm curious why we're seeing those errors. |
I think we are mixing things, we are throwing an error on a possible function flow (from the function docs: |
I was originally just returning true for these, but it was brought up that we wanted to throw the errors so I console logged them. I believe at the end of the day it just doesnt have access to a file and throws the error from fs. |
@corwintines & I dug in - we can remove the fs.readFileSync error. |
Description
Changes to gatsby-node to parse markdown and json files for translation.
With JSON we now check:
With Markdown we now check:
Related Issue