Skip to content
This repository was archived by the owner on Mar 28, 2018. It is now read-only.

Commit c366136

Browse files
committed
Hello, world
0 parents  commit c366136

File tree

8 files changed

+185
-0
lines changed

8 files changed

+185
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- '7'

index.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict'
2+
const got = require('got')
3+
const cheerio = require('cheerio')
4+
const getInline = require('get-inline-styles')
5+
const stripComments = require('strip-html-comments')
6+
const stripWayback = require('strip-wayback-toolbar')
7+
8+
module.exports = (url, timestamp) => {
9+
let waybackUrl = null
10+
11+
return getAvailableUrl(url, timestamp)
12+
.then(url => waybackUrl = url && got(url))
13+
.then(res => stripWayback(res.body))
14+
.then(getCss)
15+
.then(getCssFromLinks)
16+
.then(aggregateCss)
17+
}
18+
19+
const aggregateCss = css => {
20+
css.css = css.links.concat(css.styles).join(' ')
21+
22+
return css
23+
}
24+
25+
const getCssFromLinks = css => {
26+
const baseUrl = 'http://web.archive.org'
27+
const linkCss = []
28+
29+
const px = css.links.map(link => {
30+
const loc = `${baseUrl}${link}`
31+
console.log(loc)
32+
33+
return got(loc).then(res => linkCss.push(res.body))
34+
})
35+
36+
return Promise.all(px)
37+
.then(() => ({
38+
styles: css.styles,
39+
inline: css.inline,
40+
links: linkCss
41+
}))
42+
}
43+
44+
const getCss = html => {
45+
const $ = cheerio.load(html)
46+
47+
const results = {
48+
links: [],
49+
styles: [],
50+
inline: getInline(html)
51+
}
52+
53+
$('style').each(function () {
54+
results.styles.push(stripComments($(this).text()))
55+
})
56+
57+
$('link[rel=stylesheet]').each(function () {
58+
results.links.push($(this).attr('href'))
59+
})
60+
61+
return results
62+
}
63+
64+
const getAvailableUrl = (url, timestamp) => {
65+
const availabilityUrl = `http://archive.org/wayback/available?url=${url}&timestamp=${timestamp}`
66+
67+
return got(availabilityUrl, { json: true })
68+
.then(res => res.body.archived_snapshots.closest)
69+
.then(closest => closest.available && closest.url)
70+
}

license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 John Otander
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "wayback-css",
3+
"description": "Get the css for a wayback machine url",
4+
"author": "John Otander",
5+
"version": "0.1.0",
6+
"main": "index.js",
7+
"files": [
8+
"index.js"
9+
],
10+
"scripts": {
11+
"test": "ava"
12+
},
13+
"repository": "johnotander/wayback-css",
14+
"keywords": [],
15+
"license": "MIT",
16+
"dependencies": {
17+
"cheerio": "^0.22.0",
18+
"get-inline-styles": "^1.0.0",
19+
"got": "^6.6.3",
20+
"is-blank": "^1.1.0",
21+
"strip-html-comments": "^1.0.0",
22+
"strip-wayback-toolbar": "^1.0.0",
23+
"ua-string": "^1.0.0"
24+
},
25+
"devDependencies": {
26+
"ava": "*"
27+
}
28+
}

readme.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# wayback-css [![Build Status](https://secure.travis-ci.org/johnotander/wayback-css.svg?branch=master)](https://travis-ci.org/johnotander/wayback-css) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
2+
3+
Get the css for a wayback machine url.
4+
5+
## Installation
6+
7+
```bash
8+
npm install --save wayback-css
9+
```
10+
11+
## Usage
12+
13+
```javascript
14+
const waybackCss = require('wayback-css')
15+
16+
waybackCss('google.com', '20151221') // => YYYYMMDDhhss timestamp format
17+
.then(doStuff)
18+
.catch(handleError)
19+
```
20+
21+
## License
22+
23+
MIT
24+
25+
## Contributing
26+
27+
1. Fork it
28+
2. Create your feature branch (`git checkout -b my-new-feature`)
29+
3. Commit your changes (`git commit -am 'Add some feature'`)
30+
4. Push to the branch (`git push origin my-new-feature`)
31+
5. Create new Pull Request
32+
33+
Crafted with <3 by John Otander ([@4lpine](https://twitter.com/4lpine)).
34+
35+
***
36+
37+
> This package was initially generated with [yeoman](http://yeoman.io) and the [p generator](https://github.com/johnotander/generator-p.git).

test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test from 'ava'
2+
import waybackCss from './'
3+
4+
test('returns css from a wayback url', async t => {
5+
t.plan(4)
6+
7+
const results = await waybackCss('johnotander.com', '20151221')
8+
9+
t.truthy(results.css)
10+
t.truthy(results.styles)
11+
t.truthy(results.links)
12+
t.truthy(results.inline)
13+
})

0 commit comments

Comments
 (0)