Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": ["node", "node/style-guide", "prettier"],
"rules": {
"import/no-commonjs": false,
"import/no-commonjs": 0,
"no-console": "off"
}
}
2 changes: 2 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.10
14
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "8.10"
- "14.15.5"
before_script: npm test
script: ./ci-build.sh
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ⛔️ ARCHIVED - we are now using static site generation https://github.com/code-star/codestar-website-next

[![Build Status](https://travis-ci.org/code-star/codestar-website-functions.svg?branch=test)](https://travis-ci.org/code-star/codestar-website-functions)

<img align=center src=https://cloud.githubusercontent.com/assets/4116708/12473911/e67fdd44-c016-11e5-9c21-5714e07549fe.png width=450 />
Expand Down Expand Up @@ -102,6 +104,7 @@ https://docs.travis-ci.com/user/deployment/lambda

## Deploying

<!-- TODO replace by Github actions -->
**Note** that deployment should only be done by [Travis CI](https://travis-ci.org/code-star/codestar-website-functions).

- New features must be added by pull request to the `test` branch
Expand Down
21,856 changes: 13,425 additions & 8,431 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@
"version": "1.0.0-alpha.1",
"private": true,
"dependencies": {
"got": "^9.3.2",
"fast-xml-parser": "^3.18.0",
"got": "^11.8.1",
"oauth": "^0.9.15"
},
"engines": {
"npm": "5.6.0",
"node": "8.10.0"
},
"type": "commonjs",
"scripts": {
"build": "sls package --verbose",
"docs": "documentation build src/* -f md > API.md",
"lint": "eslint ./src/**/*",
"test": "npm run lint && nyc ava src/**/*.test.js",
"prettier": "prettier --write ./src/**/*.{js,ts}",
"prepush": "npm test",
"precommit": "npm run docs && npm run prettier"
"prettier": "prettier --write ./src/**/*.{js,ts}"
},
"prettier": {
"singleQuote": true,
"trailingComma": "es5"
},
"devDependencies": {
"ava": "^1.0.0-rc.2",
"documentation": "^8.1.2",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-recommended": "^4.0.0",
"husky": "^1.3.1",
"nyc": "^13.1.0",
"prettier": "^1.15.2",
"serverless": "^1.39.1",
"sinon": "^7.1.1"
"ava": "^3.15.0",
"documentation": "^13.1.1",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-recommended": "^4.1.0",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"serverless": "^2.25.0",
"sinon": "^9.2.4"
},
"husky": {
"hooks": {
"pre-commit": "npm run docs && npm run prettier",
"pre-push": "npm test"
}
}
}
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ service: codestar-nl-serverless

provider:
name: aws
runtime: nodejs8.10
runtime: nodejs14.x
region: eu-west-1
stage: test
iamRoleStatements:
Expand Down
24 changes: 9 additions & 15 deletions src/get-publications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// Use `got` instead of using `https` (intransparent syntax) or `request-promise` (bloated)
const got = require('got');
const parser = require('fast-xml-parser');
const util = require('../util');

const GET_PUBLICATIONS_URL =
'https://medium.com/codestar-blog/latest?format=json';
const GET_PUBLICATIONS_URL = 'https://medium.com/feed/codestar-blog';

/**
* @description Lambda function getPublications
Expand Down Expand Up @@ -39,21 +39,15 @@ module.exports.getPublications = async (event, context, callback) => {
try {
const headers = util.safeGetHeaders(event.headers.origin);
const response = await got(GET_PUBLICATIONS_URL);
// Strip security header
const saneResponse = response.body.substr(16);
const responseJson = JSON.parse(saneResponse);
const posts = responseJson.payload.posts;
const users = responseJson.payload.references.User;
const jsonObj = parser.parse(response.body);
const posts = jsonObj.rss.channel.item;
const simplePosts = posts.map(post => ({
id: post.id,
id: post.guid,
title: post.title,
author: users[post.creatorId].name,
authorImg: users[post.creatorId].imageId,
latestPublishedAt: post.latestPublishedAt,
uniqueSlug: post.uniqueSlug,
// TODO filter paragraphs that are empty or equal to the title
paragraphs: post.previewContent.bodyModel.paragraphs.map(p => p.text),
previewImgId: post.virtuals.previewImage.imageId,
author: post['dc:creator'],
latestPublishedAt: post.pubDate,
uniqueSlug: post.link,
paragraphs: post['content:encoded'],
}));
callback(null, {
statusCode: 200,
Expand Down
6 changes: 3 additions & 3 deletions src/get-publications/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPublications } from './index';
import test from 'ava';
const { getPublications } = require('./index');
const test = require('ava');

test('Calls callback with array if successful', async t => {
t.plan(1);
Expand All @@ -8,7 +8,7 @@ test('Calls callback with array if successful', async t => {
await getPublications(
{
headers: {
origin: 'https://www.codestar.nl',
origin: 'https://code-star.github.io',
},
body: JSON.stringify({}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// API calls only over HTTPS!
const allowedOrigins = ['https://www.codestar.nl', 'https://test.codestar.nl'];
const allowedOrigins = ['https://code-star.github.io', 'https://code-star.github.io/codestar-website-react/'];

// Response headers
const headers = origin => ({
Expand Down
4 changes: 2 additions & 2 deletions test/staticSiteMailer-dummy-payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"content-type": "text/plain;charset=UTF-8",
"dnt": "1",
"Host": "DUMMY.execute-api.eu-west-1.amazonaws.com",
"origin": "https://www.codestar.nl",
"origin": "https://code-star.github.io",
"pragma": "no-cache",
"Referer": "https://www.codestar.nl/codestar-website-react/contact",
"Referer": "https://code-star.github.io/codestar-website-react/contact",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0",
"Via": "2.0 12f.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "asdfsf245=",
Expand Down