Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
This adds a README.md file containing information about the project,including steps for Installation,languages,usage,getting involved,Support,Authors,and License.It helps users to setup and use this project.

Closes #2
  • Loading branch information
learneradarsh committed Dec 28, 2017
1 parent 8f027dd commit e8a225f
Show file tree
Hide file tree
Showing 30 changed files with 11,659 additions and 4,315 deletions.
10 changes: 5 additions & 5 deletions .coafile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[all]
files = **.js, **.json, **.css, **.yml, **.html, .eslintrc
ignore = node_modules/**, out/**, package-lock.json
ignore = node_modules/**, out/**, tests/__data__/**, package-lock.json
max_line_length = 80
use_spaces = True

Expand All @@ -9,21 +9,21 @@ bears = SpaceConsistencyBear
default_actions = *: ApplyPatchAction

[all.linelength]
ignore += **.html, static/js/i18n/**.json, package.json
ignore += **.html, static/i18n/**.json, package.json
bears = LineLengthBear

[all.links]
bears = InvalidLinkBear
link_ignore_regex = (github\.com|\{|\$)

[js]
files = lib/**/*.js, static/js/**/*.js
files = lib/**/*.js, src/js/**/*.js
bears = ESLintBear
eslint_config = .eslintrc
default_actions = *: ApplyPatchAction

[css]
files = static/css/*.css
files = src/styles/*.css
bears = StyleLintBear

[html]
Expand All @@ -33,7 +33,7 @@ htmllint_ignore = optional

[json]
files = *.json
ignore = package-lock.json
ignore = tests/__data__/**, package-lock.json
bears = JSONFormatBear
indent_size = 2
default_actions = *: ApplyPatchAction
Expand Down
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
jquery: true
parserOptions:
ecmaVersion: 2017
sourceType: module
plugins:
- prettier
extends:
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
out/*
!out/.keep
out
yarn.lock
.DS_Store
**.orig
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Google Code-in Leaders
***
This is a website to show the current leaders from all organizations in GCI.
***
* [Installation](#installation)
* [Languages](#languages)
* [Usage](#usage)
* [Getting Involved](#getting-involved)
* [Support](#support)
* [Authors](#authors)
* [License](#license)
***
### Installation
```
npm install
```
***
### Languages:
* Node.js
* JSON
***
### Usage:
```
npm run build
```
***
### Getting Involved
If you would like to be a part of the coala community, you can check out our [Getting In Touch](http://coala.readthedocs.io/en/latest/Help/Getting_In_Touch.html) page or ask us at our active Gitter channel, where we have maintainers from all over the world. We appreciate any help!
***
### Support
Feel free to contact us at our [Gitter channel](https://gitter.im/coala/coala), we'd be happy to help!
***
### Authors
You can contact to author for more information.
[blazeu](mailto:[email protected])
***
### License
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
***
29 changes: 26 additions & 3 deletions lib/gather.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
const fetch = require('node-fetch')
const fs = require('fs')

const GITHUB_CONTENT = 'https://raw.githubusercontent.com'

async function getData() {
const res = await fetch(
'https://raw.githubusercontent.com/coala/gci-leaders/gh-pages/data.min.json'
`${GITHUB_CONTENT}/coala/gci-leaders/gh-pages/data.min.json`
)

try {
const data = await res.json()
fs.writeFileSync(`${__dirname}/../out/data.min.json`, JSON.stringify(data))
} catch (e) {
console.warn('Could not gather data.min.json')
}
}

async function getFeedItems() {
const res = await fetch(
`${GITHUB_CONTENT}/coala/gci-leaders/gh-pages/feed_items.json`
)

const data = await res.json()
fs.writeFileSync(`${__dirname}/../out/data.min.json`, JSON.stringify(data))
try {
const items = await res.json()
fs.writeFileSync(
`${__dirname}/../out/feed_items.json`,
JSON.stringify(items)
)
} catch (e) {
console.warn('Could not gather feed_items.json')
}
}

getData()
getFeedItems()
18 changes: 11 additions & 7 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const fs = require('fs')
const Mustache = require('mustache')
const ncp = require('ncp').ncp
const mapKeys = require('lodash.mapkeys')
const orgs = require('../out/data.json')
const dates = require('../out/dates.json')
const planet = require('../out/blog_planet.json')
const manifest = require('../out/manifest.json')

const time = fs.statSync(`${__dirname}/../out/data.json`).mtime
const datetime = new Date(time).toUTCString()
Expand All @@ -12,18 +13,20 @@ const rootURL = process.env.URL
const competitionOpen = new Date(dates.competition_open_starts)
const noClaims = new Date(dates.competition_open_ends)

ncp('static', 'out', err => {
if (err) {
console.error(err)
}
})

const noLeader = []
const withLeader = orgs.filter(org => {
if (!org.leaders.length) noLeader.push(org)
return org.leaders.length
})

/*
* Replace dot in manifest key with dash
* because mustache can't escape dot
*/
const assets = mapKeys(manifest, (val, key) => {
return key.replace('.', '-')
})

fs.writeFileSync(
`${__dirname}/../out/index.html`,
Mustache.render(fs.readFileSync('templates/main.html').toString(), {
Expand All @@ -33,6 +36,7 @@ fs.writeFileSync(
noLeader,
competitionOpen,
noClaims,
assets,
})
)

Expand Down
20 changes: 20 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const glob = require('glob')
const fs = require('fs')

const rss = require('./rss')
;(async () => {
const files = glob.sync(`${__dirname}/../out/*.json`)
const fileContents = files.map(f => JSON.parse(fs.readFileSync(f).toString()))

const data = {}
files.forEach((f, index) => {
const name = f.split('/')[f.split('/').length - 1].replace('.json', '')
data[name] = fileContents[index]
})

data.data_updated = fs.statSync(`${__dirname}/../out/data.json`).mtime

const rssResult = rss(data)
fs.writeFileSync(`${__dirname}/../out/feed_items.json`, rssResult.feed_items)
fs.writeFileSync(`${__dirname}/../out/feed.xml`, rssResult.feed_xml)
})()
190 changes: 190 additions & 0 deletions lib/rss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
const RSS = require('rss')
const generateDiff = require('deep-diff').diff

function createLeadersHash(array) {
return array.reduce((hash, elem) => {
hash[elem.id] = elem
return hash
}, {})
}

function createOrgHash(array) {
let rank = 0
return array.reduce((hash, elem) => {
rank++
elem.rank = rank
elem.leaders = createLeadersHash(elem.leaders)
hash[elem.slug] = elem
return hash
}, {})
}

module.exports = ({
data: newData,
data_old: oldData,
feed_items: current,
data_updated: dataUpdated,
}) => {
const oldOrgs = createOrgHash(oldData)
const newOrgs = createOrgHash(newData)

if (oldOrgs && newOrgs) {
const diffs = generateDiff(oldOrgs, newOrgs) || []

const feedItems = current ? current.items : []

const currentUpdated = new Date(current ? current.lastUpdated : '')
if (currentUpdated.getTime() !== dataUpdated.getTime()) {
diffs.forEach(({ kind, path, lhs, rhs, item }) => {
const organization = oldOrgs[path[0]]

const itemPath = path.slice(1)
const stringPath = itemPath.join('/')
const finalProperty = itemPath[itemPath.length - 1]

let title = ''

if (itemPath[0] === 'leaders' && itemPath.length === 2) {
if (kind === 'N') {
title = `New Leader for ${organization.name}`
} else if (kind === 'D') {
title = `Leader Removed from ${organization.name}`
}

const user = rhs || lhs

return feedItems.push({
title,
description: `${organization.name} ${
kind === 'N' ? 'added' : 'removed'
} ${user.display_name} ${
kind === 'N' ? 'to' : 'from'
} the leaderboard.`,
date: dataUpdated,
custom_elements: [
{
'org:name': organization.name,
},
{
'org:slug': organization.slug,
},
{
'org:id': organization.id,
},
{
'property:path': stringPath,
},
{
'property:type': kind === 'N' ? 'addition' : 'deletion',
},
{
'property:display_name': user.display_name,
},
{
'property:id': user.id,
},
{
'property:github_account': user.github_account,
},
],
})
}

if (itemPath[0] === 'leaders') {
return
}

if (finalProperty === 'completed_task_instance_count') {
title = `Completed Tasks Updated for ${organization.name}`
} else if (finalProperty === 'rank') {
title = `Organization Rank Updated for ${organization.name}`
} else {
title = `Updated "${finalProperty}" for ${organization.name}`
}

if (kind === 'A') {
return feedItems.push({
title,
date: dataUpdated,
custom_elements: [
{
'org:name': organization.name,
},
{
'org:slug': organization.slug,
},
{
'org:id': organization.id,
},
{
'property:path': stringPath,
},
{
'property:type': item.kind === 'N' ? 'addition' : 'deletion',
},
{
'property:item': item.rhs,
},
],
})
}

return feedItems.push({
title,
description: `${
organization.name
} changed ${finalProperty} from ${lhs} to ${rhs}.`,
date: dataUpdated,
custom_elements: [
{
'org:name': organization.name,
},
{
'org:slug': organization.slug,
},
{
'org:id': organization.id,
},
{
'property:path': stringPath,
},
{
'property:type': 'change',
},
{
'property:old': lhs,
},
{
'property:new': rhs,
},
],
})
})

const feed = new RSS({
title: 'Google Code-in Leaders',
description: 'A feed for Google Code-in updates',
site_url: process.env.URL || 'https://gci-leaders.netlify.com',
feed_url: `${process.env.URL ||
'https://gci-leaders.netlify.com'}/feed.xml`,
pubDate: new Date(),
custom_namespaces: {
org: 'https://g.co/gci',
property: 'https://g.co/gci',
},
})

feedItems.forEach(item => feed.item(item))

const feedData = {
items: feedItems,
lastUpdated: dataUpdated,
}

return {
feed_items: JSON.stringify(feedData),
feed_xml: feed.xml(),
}
}
}
}
Loading

0 comments on commit e8a225f

Please sign in to comment.