Skip to content

Commit 87ebf0e

Browse files
committed
chore: release v0.1.0
1 parent 8bdfba5 commit 87ebf0e

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

GeoPattern.vue

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<div class="geo-pattern" :style="style">
3+
<slot />
4+
</div>
5+
</template>
6+
7+
<script>
8+
import gp from 'geopattern'
9+
10+
export default {
11+
name: 'GeoPattern',
12+
props: {
13+
// Given array elements is hexadecimal color value [0-F]
14+
colorHexs: { type: Array, default: () => ['3', '9', 'C'] },
15+
// Controls the relative background color of the generated image.
16+
baseColor: { type: String, default: '#933c3c' }
17+
},
18+
computed: {
19+
// Will be used as the seed for generation
20+
seed () {
21+
return this.$page && this.$page.title + new Date().toString()
22+
},
23+
style () {
24+
return {
25+
'background-image': this.getPattern()
26+
}
27+
}
28+
},
29+
methods: {
30+
getPattern () {
31+
return gp.generate(this.seed, {
32+
color: this.getRandomColor(this.colorHexs),
33+
baseColor: this.baseColor
34+
}).toDataUrl()
35+
},
36+
getRandomColor (hexs) {
37+
const shuffle = ([...arr]) => {
38+
let m = arr.length
39+
while (m) {
40+
let temp = null
41+
const i = Math.floor(Math.random() * m--)
42+
temp = arr[m]
43+
arr[m] = arr[i]
44+
arr[i] = temp
45+
}
46+
return arr
47+
}
48+
return shuffle(hexs).join('')
49+
}
50+
}
51+
}
52+
</script>
53+
54+
<style scoped>
55+
.geo-pattern {
56+
transition: all 0.5s ease-in-out;
57+
}
58+
</style>

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Vuepress Plugin GeoPattern
2+
3+
Register a global `<GeoPattern />` component for VuePress.
4+
5+
This component generate a beautiful random geometric pattern & random color images from a string you given.
6+
7+
> This plugin is a adaptor of [geopattern](https://github.com/btmills/geopattern)
8+
9+
## See Demo on CodeSandbox
10+
11+
[![Edit vuepress-plugin-geopattern](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/fast-pine-42vz4?fontsize=14&hidenavigation=1&theme=dark)
12+
13+
## Installation
14+
15+
```bash
16+
yarn add vuepress-plugin-geopattern -S
17+
or
18+
npm i vuepress-plugin-disqus -S
19+
```
20+
21+
## Register the plugin
22+
23+
```js
24+
...
25+
module.exports = {
26+
...,
27+
plugins: {
28+
['geopattern']
29+
},
30+
...
31+
}
32+
...
33+
```
34+
35+
## Usage
36+
37+
> Only background image, you must give the height of the element
38+
39+
```vue
40+
<GeoPattern style="height: 80px;" />
41+
```
42+
43+
> With the custom slot, in the case, you can let the slot element control the pattern's height
44+
45+
```vue
46+
<GeoPattern>
47+
<div class="posts-header">
48+
All Posts
49+
</div>
50+
</GeoPattern>
51+
```
52+
53+
## API
54+
55+
> colorHexs is a new props for this component, I believe that three hexadecimal color value[0-F] can generate beautiful colors in random way.
56+
57+
| Props | Description | Type | Default |
58+
| :---: | :---------: | :--: | :-----: |
59+
| colorHexs | Given array elements is hexadecimal color value [0-F] | Array | `['3', '9' 'C' ]` |
60+
| baseColor | Controls the relative background color of the generated image. | String | `933c3c` |
61+
62+
## Slot
63+
64+
`<GeoPattern />` component provide a custom slot, you can write some element on the generated pattern.
65+
66+
## License
67+
68+
MIT

enhanceAppFile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import GeoPattern from './GeoPattern.vue'
2+
3+
export default ({ Vue }) => {
4+
Vue.component('GeoPattern', GeoPattern)
5+
}

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
enhanceAppFiles: [
5+
path.resolve(__dirname, 'enhanceAppFile.js')
6+
],
7+
8+
chainWebpack (config, isServer) {
9+
// to make geopattern work
10+
if (!isServer) {
11+
config.node.set('Buffer', false)
12+
}
13+
}
14+
}

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "vuepress-plugin-geopattern",
3+
"version": "0.1.0",
4+
"description": "Generate beautiful random geometric pattern background images.",
5+
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/xiaoluoboding/vuepress-plugin-geopattern.git"
9+
},
10+
"keywords": [
11+
"vuepress",
12+
"plugin",
13+
"pattern"
14+
],
15+
"author": "xiaoluoboding",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/xiaoluoboding/vuepress-plugin-geopattern/issues"
19+
},
20+
"homepage": "https://github.com/xiaoluoboding/vuepress-plugin-geopattern#readme"
21+
}

0 commit comments

Comments
 (0)