Skip to content

Commit

Permalink
chore: format files and update linting config
Browse files Browse the repository at this point in the history
  • Loading branch information
raisedadead committed Feb 17, 2022
1 parent 68198f3 commit 6403da2
Show file tree
Hide file tree
Showing 91 changed files with 1,931 additions and 1,933 deletions.
15 changes: 5 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.hbs]
insert_final_newline = false
[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false


[Makefile]
indent_style = tab
104 changes: 52 additions & 52 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
const { readFileSync, readdirSync, writeFileSync, unlinkSync } = require("fs");
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");
const fullEscaper = require("./utils/full-escaper");
const translate = require("./utils/translate");
const { readFileSync, readdirSync, writeFileSync, unlinkSync } = require('fs');
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');
const fullEscaper = require('./utils/full-escaper');
const translate = require('./utils/translate');
const {
imageShortcode,
featureImageShortcode,
} = require("./utils/shortcodes/images");
const cacheBusterShortcode = require("./utils/shortcodes/cache-buster");
const sitemapFetcherShortcode = require("./utils/shortcodes/sitemap-fetcher");
const createJsonLdShortcode = require("./utils/shortcodes/create-json-ld");
featureImageShortcode
} = require('./utils/shortcodes/images');
const cacheBusterShortcode = require('./utils/shortcodes/cache-buster');
const sitemapFetcherShortcode = require('./utils/shortcodes/sitemap-fetcher');
const createJsonLdShortcode = require('./utils/shortcodes/create-json-ld');
const {
publishedDateShortcode,
timeAgoShortcode,
buildDateFormatterShortcode,
fullYearShortcode,
toISOStringShortcode,
} = require("./utils/shortcodes/dates");
const { currentLocale_i18n } = require("./config");
const sitePath = require("./utils/site-path");
toISOStringShortcode
} = require('./utils/shortcodes/dates');
const { currentLocale_i18n } = require('./config');
const sitePath = require('./utils/site-path');

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

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

// Minify inline JS
config.addNunjucksAsyncFilter("jsMin", jsMin);
config.addNunjucksAsyncFilter('jsMin', jsMin);

// Empty manifest to load new versions of cached files
// for hot reloading
config.on("beforeBuild", () => {
config.on('beforeBuild', () => {
manifest = {};
});

// Minify CSS and remove ads.txt from Chinese build
config.on("afterBuild", () => {
const path = "./dist/assets/css";
config.on('afterBuild', () => {
const path = './dist/assets/css';
const cssFiles = readdirSync(path);

cssFiles.forEach((filename) => {
cssFiles.forEach(filename => {
const fullPath = `${path}/${filename}`;
const content = readFileSync(fullPath);

writeFileSync(fullPath, cssMin(content));
});

if (currentLocale_i18n === "chinese") unlinkSync("./dist/ads.txt");
if (currentLocale_i18n === 'chinese') unlinkSync('./dist/ads.txt');
});

// RSS and AMP plugins
config.addPlugin(pluginRSS);

config.addNunjucksShortcode("image", imageShortcode);
config.addNunjucksShortcode('image', imageShortcode);

config.addNunjucksShortcode("featureImage", featureImageShortcode);
config.addNunjucksShortcode('featureImage', featureImageShortcode);

config.addNunjucksShortcode("cacheBuster", cacheBusterShortcode);
config.addNunjucksShortcode('cacheBuster', cacheBusterShortcode);

config.addNunjucksShortcode("t", translate);
config.addNunjucksShortcode('t', translate);

config.addNunjucksShortcode("fullEscaper", fullEscaper);
config.addNunjucksShortcode('fullEscaper', fullEscaper);

config.addNunjucksAsyncShortcode("createJsonLd", createJsonLdShortcode);
config.addNunjucksAsyncShortcode('createJsonLd', createJsonLdShortcode);

config.addNunjucksAsyncShortcode("sitemapFetcher", sitemapFetcherShortcode);
config.addNunjucksAsyncShortcode('sitemapFetcher', sitemapFetcherShortcode);

// Date and time shortcodes and filters
config.addNunjucksShortcode("publishedDate", publishedDateShortcode);
config.addNunjucksShortcode('publishedDate', publishedDateShortcode);

config.addNunjucksShortcode("timeAgo", timeAgoShortcode);
config.addNunjucksShortcode('timeAgo', timeAgoShortcode);

config.addNunjucksShortcode(
"buildDateFormatter",
'buildDateFormatter',
buildDateFormatterShortcode
);

config.addNunjucksShortcode("fullYear", fullYearShortcode);
config.addNunjucksShortcode('fullYear', fullYearShortcode);

config.addNunjucksShortcode("toISOString", toISOStringShortcode);
config.addNunjucksShortcode('toISOString', toISOStringShortcode);

// Selectively show comments section
config.addFilter("commentsEnabled", (tagsArr) => {
return !tagsArr.map((tag) => tag.name).includes("#disable-comments");
config.addFilter('commentsEnabled', tagsArr => {
return !tagsArr.map(tag => tag.name).includes('#disable-comments');
});

// Check for next page before showing 'Load More Articles' button
config.addFilter("nextPageExists", (href) => {
config.addFilter('nextPageExists', href => {
const nextPageRegExp = /\/\d+\/$/g;
return nextPageRegExp.test(href);
});
Expand All @@ -102,40 +102,40 @@ module.exports = function (config) {
config.setBrowserSyncConfig({
callbacks: {
ready: (err, bs) => {
const content_404 = readFileSync("dist/404.html");
const content_RSS = readFileSync("dist/rss.xml");
const content_404 = readFileSync('dist/404.html');
const content_RSS = readFileSync('dist/rss.xml');

bs.addMiddleware("*", (req, res) => {
bs.addMiddleware('*', (req, res) => {
if (req.url.match(/^\/rss\/?$/)) {
res.writeHead(302, { "Content-Type": "text/xml; charset=UTF-8" });
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" });
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' });

// Provides the 404 content without redirect
res.write(content_404);
res.end();
}
});
},
startPath: sitePath,
},
startPath: sitePath
}
});

// Eleventy configuration
return {
dir: {
input: "src",
output: "dist",
input: 'src',
output: 'dist'
},

// Files read by Eleventy, add as needed
templateFormats: ["css", "njk"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
pathPrefix: sitePath,
templateFormats: ['css', 'njk'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
pathPrefix: sitePath
};
};
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Comment out the line below to run Prettier against the files in the final build
dist/
package-lock.json
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module.exports = {
node: true,
browser: true,
commonjs: true,
es6: true,
es6: true
},
extends: ["eslint:recommended", "plugin:cypress/recommended", "prettier"],
extends: ['eslint:recommended', 'plugin:cypress/recommended', 'prettier'],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: 2020
},
rules: {},
rules: {}
};
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache: 'npm'

- name: Set environment variables
run: cp sample.env .env
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/deploy-eng.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ jobs:
uses: azure/webapps-deploy@v2
with:
app-name: freecodecamp-news-${{ matrix.site_tlds }}-${{ matrix.languages }}
images: ${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:${{ github.sha }}
images:
${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{
matrix.languages }}:${{ github.sha }}

- name: Remove Old images
run: |
Expand Down
24 changes: 8 additions & 16 deletions .github/workflows/deploy-i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,34 @@ jobs:

ENGLISH_GHOST_API_URL: ${{ secrets.ENGLISH_GHOST_API_URL }}
ENGLISH_GHOST_API_VERSION: ${{ secrets.ENGLISH_GHOST_API_VERSION }}
ENGLISH_GHOST_CONTENT_API_KEY:
${{ secrets.ENGLISH_GHOST_CONTENT_API_KEY }}
ENGLISH_GHOST_CONTENT_API_KEY: ${{ secrets.ENGLISH_GHOST_CONTENT_API_KEY }}

CHINESE_GHOST_API_URL: ${{ secrets.CHINESE_GHOST_API_URL }}
CHINESE_GHOST_API_VERSION: ${{ secrets.CHINESE_GHOST_API_VERSION }}
CHINESE_GHOST_CONTENT_API_KEY:
${{ secrets.CHINESE_GHOST_CONTENT_API_KEY }}
CHINESE_GHOST_CONTENT_API_KEY: ${{ secrets.CHINESE_GHOST_CONTENT_API_KEY }}

ESPANOL_GHOST_API_URL: ${{ secrets.ESPANOL_GHOST_API_URL }}
ESPANOL_GHOST_API_VERSION: ${{ secrets.ESPANOL_GHOST_API_VERSION }}
ESPANOL_GHOST_CONTENT_API_KEY:
${{ secrets.ESPANOL_GHOST_CONTENT_API_KEY }}
ESPANOL_GHOST_CONTENT_API_KEY: ${{ secrets.ESPANOL_GHOST_CONTENT_API_KEY }}

ITALIAN_GHOST_API_URL: ${{ secrets.ITALIAN_GHOST_API_URL }}
ITALIAN_GHOST_API_VERSION: ${{ secrets.ITALIAN_GHOST_API_VERSION }}
ITALIAN_GHOST_CONTENT_API_KEY:
${{ secrets.ITALIAN_GHOST_CONTENT_API_KEY }}
ITALIAN_GHOST_CONTENT_API_KEY: ${{ secrets.ITALIAN_GHOST_CONTENT_API_KEY }}

PORTUGUESE_GHOST_API_URL: ${{ secrets.PORTUGUESE_GHOST_API_URL }}
PORTUGUESE_GHOST_API_VERSION: ${{ secrets.PORTUGUESE_GHOST_API_VERSION }}
PORTUGUESE_GHOST_CONTENT_API_KEY:
${{ secrets.PORTUGUESE_GHOST_CONTENT_API_KEY }}
PORTUGUESE_GHOST_CONTENT_API_KEY: ${{ secrets.PORTUGUESE_GHOST_CONTENT_API_KEY }}

JAPANESE_GHOST_API_URL: ${{ secrets.JAPANESE_GHOST_API_URL }}
JAPANESE_GHOST_API_VERSION: ${{ secrets.JAPANESE_GHOST_API_VERSION }}
JAPANESE_GHOST_CONTENT_API_KEY:
${{ secrets.JAPANESE_GHOST_CONTENT_API_KEY }}
JAPANESE_GHOST_CONTENT_API_KEY: ${{ secrets.JAPANESE_GHOST_CONTENT_API_KEY }}

ARABIC_GHOST_API_URL: ${{ secrets.ARABIC_GHOST_API_URL }}
ARABIC_GHOST_API_VERSION: ${{ secrets.ARABIC_GHOST_API_VERSION }}
ARABIC_GHOST_CONTENT_API_KEY: ${{ secrets.ARABIC_GHOST_CONTENT_API_KEY }}

ADS_ENABLED: ${{ secrets.ADS_ENABLED }}
GOOGLE_ADSENSE_DATA_AD_CLIENT:
${{ secrets.GOOGLE_ADSENSE_DATA_AD_CLIENT }}
GOOGLE_ADSENSE_DATA_AD_CLIENT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_CLIENT }}
GOOGLE_ADSENSE_DATA_AD_SLOT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_SLOT }}

POSTS_PER_PAGE: ${{ secrets.POSTS_PER_PAGE }}
Expand Down Expand Up @@ -138,8 +131,7 @@ jobs:
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name:
freecodecamp-news-${{ matrix.site_tlds }}-${{ matrix.languages }}
app-name: freecodecamp-news-${{ matrix.site_tlds }}-${{ matrix.languages }}
images:
${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{
matrix.languages }}:latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/node.js-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache: 'npm'

- name: Set environment variables
run: cp sample.env .env
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache: 'npm'

- name: Set environment variables
run: cp sample.env .env
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"endOfLine": "lf",
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"arrowParens": "avoid"
}
39 changes: 19 additions & 20 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
BSD 3-Clause License

Copyright (c) 2021, freeCodeCamp.
All rights reserved.
Copyright (c) 2021, freeCodeCamp. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

- Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
- Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 6403da2

Please sign in to comment.