Skip to content

Commit

Permalink
feat: restore from delete git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Dec 24, 2018
0 parents commit f81e404
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0 (2.10.16)

- Added: Initial version
60 changes: 60 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
You want to help? You rock! Now, take a moment to be sure your contributions make sense to everyone else.

## Reporting Issues

Found a problem? Want a new feature?

- See if your issue or idea has [already been reported].
- Provide a [reduced test case] or a [live example].

Remember, a bug is a _demonstrable problem_ caused by _our_ code.

## Submitting Pull Requests

Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.

1. To begin, [fork this project], clone your fork, and add our upstream.
```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/<your-username>/PLUGIN_NAME
# Navigate to the newly cloned directory
cd PLUGIN_NAME
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/GITHUB_NAME/PLUGIN_NAME
# Install the tools necessary for development
npm install
```

2. Create a branch for your feature or fix:
```bash
# Move into a new branch for a feature
git checkout -b feature/thing
```
```bash
# Move into a new branch for a fix
git checkout -b fix/something
```

3. Be sure your code follows our practices.
```bash
# Test current code
npm run test
```

4. Push your branch up to your fork:
```bash
# Push a feature branch
git push origin feature/thing
```
```bash
# Push a fix branch
git push origin fix/something
```

5. Now [open a pull request] with a clear title and description.

[already been reported]: issues
[fork this project]: fork
[live example]: http://codepen.io/pen
[open a pull request]: https://help.github.com/articles/using-pull-requests/
[reduced test case]: https://css-tricks.com/reduced-test-cases/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License (MIT)

Copyright (c) 2016 PostHTML

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# PostHTML Plugin Boilerplate <img align="right" width="220" height="200" title="PostHTML logo" src="http://posthtml.github.io/posthtml/logo.svg">

[![NPM][npm]][npm-url]
[![Deps][deps]][deps-url]
[![Build][build]][build-badge]
[![Coverage][cover]][cover-badge]
[![Standard Code Style][style]][style-url]
[![Chat][chat]][chat-badge]

This plugin add webp supporting in your html.

Before:
``` html
<img src="image.jpg">
```

After:
``` html
<picture>
<source type="image/webp" srcset="image.jpg.webp">
<img src="image.jpg">
</picture>
```

## Install

> npm i posthtml posthtml-webp
## Usage

``` js
const fs = require('fs');
const posthtml = require('posthtml');
const posthtmlWebp = require('posthtml-webp');

posthtml()
.use(posthtmlWebp())
.process(html/*, options */)
.then(result => fs.writeFileSync('./after.html', result.html));
```

### License [MIT](LICENSE)

[npm]: https://img.shields.io/npm/v/posthtml.svg
[npm-url]: https://npmjs.com/package/posthtml

[deps]: https://david-dm.org/posthtml/posthtml.svg
[deps-url]: https://david-dm.org/posthtml/posthtml

[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/

[build]: https://travis-ci.org/posthtml/posthtml.svg?branch=master
[build-badge]: https://travis-ci.org/posthtml/posthtml?branch=master

[cover]: https://coveralls.io/repos/posthtml/posthtml/badge.svg?branch=master
[cover-badge]: https://coveralls.io/r/posthtml/posthtml?branch=master


[chat]: https://badges.gitter.im/posthtml/posthtml.svg
[chat-badge]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"
29 changes: 29 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

module.exports = function () {
return function posthtmlWebp (tree) {
tree.match({ tag: 'img' }, function (imgNode) {
if (imgNode.skip) return imgNode
return getPicture(imgNode)
})

return tree
}
}

function getPicture (imgNode) {
imgNode.skip = true
return {
tag: 'picture',
content: [
{
tag: 'source',
attrs: {
type: 'image/webp',
srcset: imgNode.attrs.src + '.webp'
}
},
imgNode
]
}
}
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "posthtml-webp",
"description": "Add webp supporting in your html",
"version": "1.0.0",
"author": "seokirill",
"ava": {
"verbose": "true"
},
"bugs": "https://github.com/posthtml/posthtml-webp/issues",
"dependencies": {
"posthtml": "^0.9.0"
},
"devDependencies": {
"ava": "^0.15.2",
"conventional-changelog": "^1.1.0",
"conventional-changelog-lint": "^1.0.0",
"husky": "^0.11.5",
"mversion": "^1.10.1",
"snazzy": "^4.0.0",
"standard": "^7.1.2"
},
"engines": {
"node": ">=4"
},
"homepage": "https://github.com/posthtml/posthtml-webp",
"keywords": [
"html",
"posthtml",
"posthtml-plugin",
"webp"
],
"license": "MIT",
"main": "lib",
"repository": "posthtml/posthtml-webp",
"scripts": {
"commitmsg": "conventional-changelog-lint -p angular -e",
"lint": "standard | snazzy",
"precommit": "npm run lint",
"release-major": "mversion major",
"release-minor": "mversion minor",
"release-patch": "mversion patch",
"test": "npm run lint && ava"
}
}
1 change: 1 addition & 0 deletions test/fixtures/basic.expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html>
1 change: 1 addition & 0 deletions test/fixtures/basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html>
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const test = require('ava')
const plugin = require('..')
const {readFileSync} = require('fs')
const path = require('path')
const posthtml = require('posthtml')
const fixtures = path.join(__dirname, 'fixtures')

test('basic', (t) => {
return compare(t, 'basic')
})

function compare (t, name) {
const html = readFileSync(path.join(fixtures, `${name}.html`), 'utf8')
const expected = readFileSync(path.join(fixtures, `${name}.expected.html`), 'utf8')

return posthtml([plugin()])
.process(html)
.then((res) => t.truthy(res.html === expected))
}

0 comments on commit f81e404

Please sign in to comment.