Skip to content

Commit f81e404

Browse files
committed
feat: restore from delete git repository
0 parents  commit f81e404

File tree

10 files changed

+242
-0
lines changed

10 files changed

+242
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0 (2.10.16)
2+
3+
- Added: Initial version

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
You want to help? You rock! Now, take a moment to be sure your contributions make sense to everyone else.
2+
3+
## Reporting Issues
4+
5+
Found a problem? Want a new feature?
6+
7+
- See if your issue or idea has [already been reported].
8+
- Provide a [reduced test case] or a [live example].
9+
10+
Remember, a bug is a _demonstrable problem_ caused by _our_ code.
11+
12+
## Submitting Pull Requests
13+
14+
Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
15+
16+
1. To begin, [fork this project], clone your fork, and add our upstream.
17+
```bash
18+
# Clone your fork of the repo into the current directory
19+
git clone https://github.com/<your-username>/PLUGIN_NAME
20+
# Navigate to the newly cloned directory
21+
cd PLUGIN_NAME
22+
# Assign the original repo to a remote called "upstream"
23+
git remote add upstream https://github.com/GITHUB_NAME/PLUGIN_NAME
24+
# Install the tools necessary for development
25+
npm install
26+
```
27+
28+
2. Create a branch for your feature or fix:
29+
```bash
30+
# Move into a new branch for a feature
31+
git checkout -b feature/thing
32+
```
33+
```bash
34+
# Move into a new branch for a fix
35+
git checkout -b fix/something
36+
```
37+
38+
3. Be sure your code follows our practices.
39+
```bash
40+
# Test current code
41+
npm run test
42+
```
43+
44+
4. Push your branch up to your fork:
45+
```bash
46+
# Push a feature branch
47+
git push origin feature/thing
48+
```
49+
```bash
50+
# Push a fix branch
51+
git push origin fix/something
52+
```
53+
54+
5. Now [open a pull request] with a clear title and description.
55+
56+
[already been reported]: issues
57+
[fork this project]: fork
58+
[live example]: http://codepen.io/pen
59+
[open a pull request]: https://help.github.com/articles/using-pull-requests/
60+
[reduced test case]: https://css-tricks.com/reduced-test-cases/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License (MIT)
2+
3+
Copyright (c) 2016 PostHTML
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 all
13+
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 THE
21+
SOFTWARE.

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# PostHTML Plugin Boilerplate <img align="right" width="220" height="200" title="PostHTML logo" src="http://posthtml.github.io/posthtml/logo.svg">
2+
3+
[![NPM][npm]][npm-url]
4+
[![Deps][deps]][deps-url]
5+
[![Build][build]][build-badge]
6+
[![Coverage][cover]][cover-badge]
7+
[![Standard Code Style][style]][style-url]
8+
[![Chat][chat]][chat-badge]
9+
10+
This plugin add webp supporting in your html.
11+
12+
Before:
13+
``` html
14+
<img src="image.jpg">
15+
```
16+
17+
After:
18+
``` html
19+
<picture>
20+
<source type="image/webp" srcset="image.jpg.webp">
21+
<img src="image.jpg">
22+
</picture>
23+
```
24+
25+
## Install
26+
27+
> npm i posthtml posthtml-webp
28+
29+
## Usage
30+
31+
``` js
32+
const fs = require('fs');
33+
const posthtml = require('posthtml');
34+
const posthtmlWebp = require('posthtml-webp');
35+
36+
posthtml()
37+
.use(posthtmlWebp())
38+
.process(html/*, options */)
39+
.then(result => fs.writeFileSync('./after.html', result.html));
40+
```
41+
42+
### License [MIT](LICENSE)
43+
44+
[npm]: https://img.shields.io/npm/v/posthtml.svg
45+
[npm-url]: https://npmjs.com/package/posthtml
46+
47+
[deps]: https://david-dm.org/posthtml/posthtml.svg
48+
[deps-url]: https://david-dm.org/posthtml/posthtml
49+
50+
[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
51+
[style-url]: http://standardjs.com/
52+
53+
[build]: https://travis-ci.org/posthtml/posthtml.svg?branch=master
54+
[build-badge]: https://travis-ci.org/posthtml/posthtml?branch=master
55+
56+
[cover]: https://coveralls.io/repos/posthtml/posthtml/badge.svg?branch=master
57+
[cover-badge]: https://coveralls.io/r/posthtml/posthtml?branch=master
58+
59+
60+
[chat]: https://badges.gitter.im/posthtml/posthtml.svg
61+
[chat-badge]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"

lib/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
module.exports = function () {
4+
return function posthtmlWebp (tree) {
5+
tree.match({ tag: 'img' }, function (imgNode) {
6+
if (imgNode.skip) return imgNode
7+
return getPicture(imgNode)
8+
})
9+
10+
return tree
11+
}
12+
}
13+
14+
function getPicture (imgNode) {
15+
imgNode.skip = true
16+
return {
17+
tag: 'picture',
18+
content: [
19+
{
20+
tag: 'source',
21+
attrs: {
22+
type: 'image/webp',
23+
srcset: imgNode.attrs.src + '.webp'
24+
}
25+
},
26+
imgNode
27+
]
28+
}
29+
}

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "posthtml-webp",
3+
"description": "Add webp supporting in your html",
4+
"version": "1.0.0",
5+
"author": "seokirill",
6+
"ava": {
7+
"verbose": "true"
8+
},
9+
"bugs": "https://github.com/posthtml/posthtml-webp/issues",
10+
"dependencies": {
11+
"posthtml": "^0.9.0"
12+
},
13+
"devDependencies": {
14+
"ava": "^0.15.2",
15+
"conventional-changelog": "^1.1.0",
16+
"conventional-changelog-lint": "^1.0.0",
17+
"husky": "^0.11.5",
18+
"mversion": "^1.10.1",
19+
"snazzy": "^4.0.0",
20+
"standard": "^7.1.2"
21+
},
22+
"engines": {
23+
"node": ">=4"
24+
},
25+
"homepage": "https://github.com/posthtml/posthtml-webp",
26+
"keywords": [
27+
"html",
28+
"posthtml",
29+
"posthtml-plugin",
30+
"webp"
31+
],
32+
"license": "MIT",
33+
"main": "lib",
34+
"repository": "posthtml/posthtml-webp",
35+
"scripts": {
36+
"commitmsg": "conventional-changelog-lint -p angular -e",
37+
"lint": "standard | snazzy",
38+
"precommit": "npm run lint",
39+
"release-major": "mversion major",
40+
"release-minor": "mversion minor",
41+
"release-patch": "mversion patch",
42+
"test": "npm run lint && ava"
43+
}
44+
}

test/fixtures/basic.expected.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html>

test/fixtures/basic.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html>

test/test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const test = require('ava')
4+
const plugin = require('..')
5+
const {readFileSync} = require('fs')
6+
const path = require('path')
7+
const posthtml = require('posthtml')
8+
const fixtures = path.join(__dirname, 'fixtures')
9+
10+
test('basic', (t) => {
11+
return compare(t, 'basic')
12+
})
13+
14+
function compare (t, name) {
15+
const html = readFileSync(path.join(fixtures, `${name}.html`), 'utf8')
16+
const expected = readFileSync(path.join(fixtures, `${name}.expected.html`), 'utf8')
17+
18+
return posthtml([plugin()])
19+
.process(html)
20+
.then((res) => t.truthy(res.html === expected))
21+
}

0 commit comments

Comments
 (0)