Skip to content

Commit

Permalink
chore: update 11ty to v2 (#843)
Browse files Browse the repository at this point in the history
Co-authored-by: scissorsneedfoodtoo <[email protected]>
  • Loading branch information
sidemt and scissorsneedfoodtoo authored Mar 25, 2024
1 parent fed1728 commit b90f650
Show file tree
Hide file tree
Showing 50 changed files with 622 additions and 2,304 deletions.
34 changes: 7 additions & 27 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { readFileSync, readdirSync, writeFileSync } = require('graceful-fs');
const { EleventyHtmlBasePlugin } = require('@11ty/eleventy');
const pluginRSS = require('@11ty/eleventy-plugin-rss');
const UpgradeHelper = require('@11ty/eleventy-upgrade-help');

const cssMin = require('./utils/transforms/css-min');
const jsMin = require('./utils/transforms/js-min');
Expand All @@ -23,8 +23,6 @@ const { currentLocale_i18n, eleventyEnv } = require('./config');
const sitePath = require('./utils/site-path');

module.exports = function (config) {
config.addPlugin(UpgradeHelper);

// Minify inline CSS
config.addFilter('cssMin', cssMin);

Expand Down Expand Up @@ -109,30 +107,12 @@ module.exports = function (config) {
});
}

// Display 404 and RSS pages in BrowserSync
config.setBrowserSyncConfig({
callbacks: {
ready: (err, bs) => {
const content_404 = readFileSync('dist/404.html');
const content_RSS = readFileSync('dist/rss.xml');

bs.addMiddleware('*', (req, res) => {
if (req.url.match(/^\/rss\/?$/)) {
res.writeHead(302, { 'Content-Type': 'text/xml; charset=UTF-8' });

// Provides the RSS feed content without redirect
res.write(content_RSS);
res.end();
} else {
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' });

// Provides the 404 content without redirect
res.write(content_404);
res.end();
}
});
},
startPath: sitePath
// Use the new Base plugin to replace the old url filter method
// so we can deploy in a different directory
config.addPlugin(EleventyHtmlBasePlugin, {
baseHref: sitePath,
filters: {
base: 'htmlBaseUrl'
}
});

Expand Down
9 changes: 3 additions & 6 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,17 @@ if (lang !== localeForGhost && localeForGhost !== 'local') {
`);
}

let computedPath;

// Config Computations
const getSiteURL = (lang, forOriginalArticle) => {
// Special handling for original article feature, where we always want the final siteURL
const computedDomain =
!siteDomain || forOriginalArticle ? 'freecodecamp.org' : siteDomain;
computedPath = lang === 'english' ? 'news' : `${lang}/news`;
const computedPath = lang === 'english' ? '/news' : `/${lang}/news`;

if (computedDomain.startsWith('localhost')) {
return `http://${computedDomain}/${computedPath}`;
return `http://${computedDomain}${computedPath}/`;
} else {
return `https://www.${computedDomain}/${computedPath}`;
return `https://www.${computedDomain}${computedPath}/`;
}
};

Expand All @@ -126,7 +124,6 @@ module.exports = Object.assign(
locales,
localeCodes,
algoliaIndices,
computedPath,
getSiteURL,
currentLocale_i18n: localeForUI || 'italian',
currentLocale_i18nISOCode: !localeCodes[localeForUI]
Expand Down
2 changes: 1 addition & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { postsPerPage } = require('./config');

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:8080/news',
baseUrl: 'http://localhost:8080/news/',
retries: 4
},
env: {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/chinese/landing/landing.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('Landing', () => {
before(() => {
// Update baseUrl to include current language
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news');
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news/');
});

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/chinese/post/ads.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const selectors = {
describe('Ads', () => {
before(() => {
// Update baseUrl to include current language
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news');
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news/');
});

beforeEach(() => {
cy.visit('/javascript-array-length');
cy.visit('/javascript-array-length/');
});

it('the adsense script should not be within the `head` element', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/chinese/post/post.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const selectors = {
describe('Post', () => {
before(() => {
// Update baseUrl to include current language
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news');
Cypress.config('baseUrl', 'http://localhost:8080/chinese/news/');
});

beforeEach(() => {
cy.visit('/javascript-array-length');
cy.visit('/javascript-array-length/');
});

it('should render', () => {
Expand Down
15 changes: 14 additions & 1 deletion cypress/e2e/english/404/404.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
const commonExpectedMeta = require('../../../fixtures/common-expected-meta.json');
const selectors = {
errorLink: "[data-test-label='error-link']"
};

describe('404', () => {
beforeEach(() => {
cy.visit('/testing-testing-1-2', { failOnStatusCode: false });
cy.visit('/testing-testing-1-2/', { failOnStatusCode: false });
});

it('should render basic components', () => {
cy.get('nav').should('be.visible');
cy.get('.banner').should('be.visible');
cy.get('footer').should('be.visible');
});

it('the error link should point to to the full URL of the landing page', () => {
cy.get(selectors.errorLink).should(
'have.attr',
'href',
commonExpectedMeta.siteUrl
);
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/english/404/i18n.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const selectors = {

describe('404 i18n', () => {
beforeEach(() => {
cy.visit('/testing-testing-1-2', { failOnStatusCode: false });
cy.visit('/testing-testing-1-2/', { failOnStatusCode: false });
});

it('the error message elements do not render their i18n keys', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/english/author/author.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const selectors = {
describe('Author page', () => {
context('General tests', () => {
beforeEach(() => {
cy.visit('/author/quincylarson');
cy.visit('/author/quincylarson/');
});

it('should render', () => {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Author page', () => {

context('Author with no profile image', () => {
beforeEach(() => {
cy.visit('/author/mrugesh');
cy.visit('/author/mrugesh/');
});

it('should render', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/author/i18n.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const selectors = {

describe('Author page i18n', () => {
it('an author page with multiple posts does not render its post count i18n key', () => {
cy.visit('/author/quincylarson');
cy.visit('/author/quincylarson/');

cy.get(selectors.authorPostCount)
.invoke('text')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/english/author/meta.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const authorExpectedMeta = {
describe('Author page metadata', () => {
context("Quincy's author page", () => {
beforeEach(() => {
cy.visit('/author/quincylarson');
cy.visit('/author/quincylarson/');
});

it('<title>', () => {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('Author page metadata', () => {

context('freeCodeCamp author page', () => {
beforeEach(() => {
cy.visit('/author/freecodecamp');
cy.visit('/author/freecodecamp/');
});

it("<meta> og:image should be set to the site's publication cover image when there's no custom banner image", () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/author/structured-data.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Author page structured data (JSON-LD)', () => {
let jsonLdObj;

beforeEach(() => {
cy.visit('/author/quincylarson');
cy.visit('/author/quincylarson/');

jsonLdObj = cy
.get('head script[type="application/ld+json"]')
Expand Down
12 changes: 11 additions & 1 deletion cypress/e2e/english/landing/landing.cy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const commonExpectedMeta = require('../../../fixtures/common-expected-meta.json');
const { loadAllPosts } = require('../../../support/utils/post-cards');

const selectors = {
postCard: "[data-test-label='post-card']",
authorList: "[data-test-label='author-list']",
authorProfileImage: "[data-test-label='profile-image']",
avatar: "[data-test-label='avatar']"
avatar: "[data-test-label='avatar']",
siteNavLogo: "[data-test-label='site-nav-logo']"
};

describe('Landing', () => {
Expand All @@ -19,6 +21,14 @@ describe('Landing', () => {
cy.get('footer').should('be.visible');
});

it('the fCC logo in the nav should link to the full URL of the landing page', () => {
cy.get(selectors.siteNavLogo).should(
'have.attr',
'href',
commonExpectedMeta.siteUrl
);
});

it("should show the author's profile image", () => {
cy.get(selectors.postCard)
.contains(
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/page/meta.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const pageExpectedMeta = {

describe('Page metadata', () => {
beforeEach(() => {
cy.visit('/thank-you-for-donating');
cy.visit('/thank-you-for-donating/');
});

it('<title>', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/english/page/page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const selectors = {
describe('Page', () => {
context('General tests', () => {
beforeEach(() => {
cy.visit('/thank-you-for-donating');
cy.visit('/thank-you-for-donating/');
});

it('should render', () => {
Expand All @@ -17,7 +17,7 @@ describe('Page', () => {

context('Embedded videos', () => {
beforeEach(() => {
cy.visit('/embedded-videos-page');
cy.visit('/embedded-videos-page/');
});

it('should render', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/page/structured-data.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Page structured data (JSON-LD)', () => {
let jsonLdObj;

beforeEach(() => {
cy.visit('/thank-you-for-donating');
cy.visit('/thank-you-for-donating/');

jsonLdObj = cy
.get('head script[type="application/ld+json"]')
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/english/post/ads.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const selectors = {
describe('Ads', () => {
context('General tests', () => {
beforeEach(() => {
cy.visit('/carbon-neutral-web3-curriculum-plans');
cy.visit('/carbon-neutral-web3-curriculum-plans/');
});

it('the adsense script should be within the `head` element', () => {
Expand All @@ -22,7 +22,7 @@ describe('Ads', () => {
context('Not authenticated', () => {
context('Ad wrappers and containers', () => {
beforeEach(() => {
cy.visit('/carbon-neutral-web3-curriculum-plans');
cy.visit('/carbon-neutral-web3-curriculum-plans/');
});

it('the post should contain at least one ad', () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Ads', () => {

context('Images and videos', () => {
beforeEach(() => {
cy.visit('/ad-layout-images-and-videos');
cy.visit('/ad-layout-images-and-videos/');
});

it('All Ghost editor images in the post body should have a max-width of 100%', () => {
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/english/post/i18n.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const selectors = {
describe('Post i18n', () => {
context('Common', () => {
beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');
});

it('the learn CTA section should not render its i18n keys', () => {
Expand All @@ -22,7 +22,7 @@ describe('Post i18n', () => {

context('Author with Twitter', () => {
beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');
});

it('the social row CTA should not render its i18n keys', () => {
Expand All @@ -41,7 +41,7 @@ describe('Post i18n', () => {

context('Author with no Twitter or bio', () => {
beforeEach(() => {
cy.visit('/no-author-profile-pic');
cy.visit('/no-author-profile-pic/');
});

it('the social row CTA should not render its i18n keys', () => {
Expand All @@ -64,7 +64,7 @@ describe('Post i18n', () => {

context('Ads', () => {
beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');
});

it('the advertisement disclaimer text should not render its i18n key', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/post/meta.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const postExpectedMeta = {

describe('Post metadata', () => {
beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');
});

it('<title>', () => {
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/english/post/post.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const selectors = {
describe('Post', () => {
context('General tests', () => {
beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');
});

it('should render', () => {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Post', () => {

context('Author with no profile picture', () => {
beforeEach(() => {
cy.visit('/no-author-profile-pic');
cy.visit('/no-author-profile-pic/');
});

it('should render', () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Post', () => {

context('Embedded videos', () => {
beforeEach(() => {
cy.visit('/embedded-videos-post');
cy.visit('/embedded-videos-post/');
});

it('should render', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/english/post/structured-data.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Post structured data (JSON-LD)', () => {
let jsonLdObj;

beforeEach(() => {
cy.visit('/announcing-rust-course-replit-web');
cy.visit('/announcing-rust-course-replit-web/');

jsonLdObj = cy
.get('head script[type="application/ld+json"]')
Expand Down
Loading

0 comments on commit b90f650

Please sign in to comment.