Skip to content

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

Merged
merged 19 commits into from
Dec 2, 2021
Merged

Conversation

corwintines
Copy link
Member

@corwintines corwintines commented Nov 10, 2021

Description

Changes to gatsby-node to parse markdown and json files for translation.

With JSON we now check:

  • if translation file exists
  • If there are the same amount of keys
  • If all the keys are the same

With Markdown we now check:

  • The parsed info structure of the mdx

Related Issue

@corwintines corwintines marked this pull request as ready for review November 15, 2021 21:37
@samajammin
Copy link
Member

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.

Copy link
Member

@pettinarip pettinarip left a 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
Copy link
Member

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?
Copy link
Member

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 = [
Copy link
Member

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("/")
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

Copy link
Member

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.

@samajammin
Copy link
Member

samajammin commented Nov 17, 2021

General note on this refactor - this now removes the concept of version for each language (since it's now defined on a page-by-page basis), so I believe we can delete that key for each language here: https://github.com/ethereum/ethereum-org-website/blob/dev/src/data/translations.json

This also means logic that relies on that should be removed/refactored, e.g. any use of getLangContentVersion. We'll also have to sort out how to rework hasTutorials - maybe we just look at the file system to see if there's any tutorials that exist for that language (i.e. does the directory src/content/translations/{lang}/developers/tutorials exist).

Edit: as a result of this we'll also need to rework how we do the contentV1Pages & contentV2Pages in gatsby-node.js, since that relies on getLangContentVersion. I think we could take a similar approach: inspect the file system to see if those markdown pages exist & if not, create the component page.

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)
Copy link
Member

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.

@github-actions github-actions bot added content 🖋️ This involves copy additions or edits review needed 👀 translation 🌍 This is related to our Translation Program labels Nov 23, 2021
? tutorial.lang === pageContext.language
: tutorial.lang === "en"
)
.filter((tutorial) => tutorial.lang === pageContext.language)
Copy link
Member

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.
Image 2021-11-23 at 9 56 08 PM

What we want is to:

  1. if the language has translated tutorials, display those
  2. 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

Copy link
Member

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).

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

@corwintines corwintines Nov 24, 2021

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
Copy link

gatsby-cloud bot commented Dec 1, 2021

Gatsby Cloud Build Report

🚩 Your build failed. See the build logs here

return <LegacyPageHome />
}
console.log(intl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

@samajammin
Copy link
Member

samajammin commented Dec 2, 2021

I think we might have to add some additional logic for the tutorial page. I believe current logic will always show the outdated banner? (we don't list every single tutorial on CrowdIn as we also have external tutorials)

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.

Copy link
Member

@samajammin samajammin left a 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])
Copy link
Member

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?

Copy link
Member

@pettinarip pettinarip left a 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

@pettinarip
Copy link
Member

@corwintines building it in my local, I see a long list of errors which I don't think adds too much value:
image

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)?

@samajammin
Copy link
Member

Nice catch @pettinarip

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)?

I think the latter - I'm curious why we're seeing those errors.

@pettinarip
Copy link
Member

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: If there is not english file, return true). I mean, that is not an error, that is an actual flow of the function.

@corwintines
Copy link
Member Author

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.

@samajammin
Copy link
Member

@corwintines & I dug in - we can remove the fs.readFileSync error.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
content 🖋️ This involves copy additions or edits translation 🌍 This is related to our Translation Program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants