Skip to content

Commit

Permalink
Add ESLint, Analytics, Sass, Offline plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
anagstef committed Jul 3, 2019
1 parent e69e173 commit a1337c4
Show file tree
Hide file tree
Showing 19 changed files with 955 additions and 275 deletions.
28 changes: 28 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/prop-types": 0,
"import/prefer-default-export": "none"
}
}
5 changes: 3 additions & 2 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import wrapWithProvider from "./wrap-with-provider";
export const wrapRootElement = wrapWithProvider;
import wrapWithProvider from './wrap-with-provider';

export const wrapRootElement = wrapWithProvider;
46 changes: 27 additions & 19 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
module.exports = {
siteMetadata: {
title: `ion-cheat-sheet`,
description: `An Ionic Framework v4 Cheat Sheet`,
author: `@anagstef`,
title: 'ion-cheat-sheet',
description: 'An Ionic Framework v4 Cheat Sheet',
author: '@anagstef',
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
resolve: 'gatsby-plugin-google-analytics',
options: {
name: `images`,
trackingId: 'UA-135029208-3',
},
},
'gatsby-plugin-react-helmet',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'images',
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
'gatsby-plugin-sass',
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
'gatsby-plugin-eslint',
{
resolve: `gatsby-plugin-manifest`,
resolve: 'gatsby-plugin-manifest',
options: {
name: `ion-cheat-sheet`,
short_name: `ion-cheat-sheet`,
start_url: `/`,
background_color: `#4d8dff`,
theme_color: `#4d8dff`,
display: `minimal-ui`,
icon: `src/images/ionic-icon.png`, // This path is relative to the root of the site.
name: 'ion-cheat-sheet',
short_name: 'ion-cheat-sheet',
start_url: '/',
background_color: '#4d8dff',
theme_color: '#4d8dff',
display: 'minimal-ui',
icon: 'src/images/ionic-icon.png',
},
},
// `gatsby-plugin-offline`,
`gatsby-plugin-netlify`
'gatsby-plugin-offline',
'gatsby-plugin-netlify',
],
}
};
48 changes: 22 additions & 26 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
const cheerio = require('cheerio');
const cloudscraper = require('cloudscraper').defaults({ resolveWithFullResponse: true });

Expand All @@ -8,14 +9,14 @@ const getLinksList = (responseBody) => {
const $ = cheerio.load(responseBody);
const linksSet = new Set();

$('ul li a').each(function() {
$('ul li a').each(function () {
linksSet.add($(this).attr('href'));
});

if (linksSet.size < 1) throw new Error('No links found');

return Array.from(linksSet).filter(str => str.charAt(0) === '/');
}
};

const getCSSVars = (responseBody) => {
const $ = cheerio.load(responseBody);
Expand All @@ -24,35 +25,30 @@ const getCSSVars = (responseBody) => {
$('#css-custom-properties + table > tbody > tr').each(function () {
cssVars.push({
cssVar: $(this).children(':first-child').text().trim(),
cssDesc: $(this).children(':nth-child(2)').text().trim()
cssDesc: $(this).children(':nth-child(2)').text().trim(),
});
});

return cssVars;
}
};

const getPageContent = (link) => {
return cloudscraper.get(mainDocsURL + link)
.then(response => {
const $ = cheerio.load(response.body);
downloadedContent.push({
title: $('h1').text().trim(),
url: mainDocsURL + link,
cssVars: getCSSVars(response.body)
});
const getPageContent = link => cloudscraper.get(mainDocsURL + link)
.then((response) => {
const $ = cheerio.load(response.body);
downloadedContent.push({
title: $('h1').text().trim(),
url: mainDocsURL + link,
cssVars: getCSSVars(response.body),
});
}

exports.onPreBootstrap = () => {
return cloudscraper.get(mainDocsURL + '/docs/api')
.then(response => {
});

const linksList = getLinksList(response.body);
const promises = linksList.map(link => getPageContent(link));
exports.onPreBootstrap = () => cloudscraper.get(`${mainDocsURL}/docs/api`)
.then((response) => {
const linksList = getLinksList(response.body);
const promises = linksList.map(link => getPageContent(link));

return Promise.all(promises);
});
}
return Promise.all(promises);
});

exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions;
Expand All @@ -67,7 +63,7 @@ exports.onCreatePage = ({ page, actions }) => {
context: {
...page.context,
downloadedContent: downloadedContent.sort((a, b) => a.title.localeCompare(b.title)),
buildDate: dateNow.getDate() + '/' + (dateNow.getMonth()+1) + '/' + dateNow.getFullYear()
}
buildDate: `${dateNow.getDate()}/${dateNow.getMonth() + 1}/${dateNow.getFullYear()}`,
},
});
}
};
5 changes: 3 additions & 2 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import wrapWithProvider from "./wrap-with-provider";
export const wrapRootElement = wrapWithProvider;
import wrapWithProvider from './wrap-with-provider';

export const wrapRootElement = wrapWithProvider;
Loading

0 comments on commit a1337c4

Please sign in to comment.