Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 149a299

Browse files
authored
chore: add a website (#99)
* use demoboard for website * tweaks * update demoboard
1 parent 4b31cdd commit 149a299

File tree

10 files changed

+639
-17
lines changed

10 files changed

+639
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The default locale name.
7070

7171
A `converter` that formats regular dates in `xxx ago` or `in xxx` style.
7272

73-
Check out our [default converter](./src/converter.js) which uses [date-fns/distance_in_words_to_now](https://date-fns.org/v1.29.0/docs/distanceInWordsToNow) under the hood.
73+
Check out our [default converter](https://github.com/egoist/vue-timeago/blob/master/src/converter.js) which uses [date-fns/distance_in_words_to_now](https://date-fns.org/v1.29.0/docs/distanceInWordsToNow) under the hood.
7474

7575
### converterOptions
7676

example/AutoUpdate.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div>
3+
<div class="box" data-title="Date">
4+
<input v-model="date" type="text" name="" id="">
5+
</div>
6+
<div class="box" data-title="Output" v-if="date">
7+
<timeago :datetime="date" :autoUpdate="1" :converterOptions="{ includeSeconds: true }" />
8+
</div>
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
data() {
15+
return {
16+
date: new Date()
17+
}
18+
}
19+
}
20+
</script>
21+
22+
<readme>
23+
Code used by this demo:
24+
25+
```html
26+
<timeago
27+
:datetime="date"
28+
:autoUpdate="1"
29+
:converterOptions="{ includeSeconds: true }"
30+
/>
31+
```
32+
33+
You can use `autoUpdate` prop to control how often this component should be updated, for example if you set it to `true`, it will be updated every 60 seconds.
34+
</readme>

example/BasicUsage.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div>
3+
<div class="box" data-title="Date">
4+
<input v-model="date" type="date" name="" id="">
5+
</div>
6+
<div class="box" data-title="Output" v-if="date">
7+
<timeago :datetime="date" />
8+
</div>
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
data() {
15+
return {
16+
date: '2019-02-12'
17+
}
18+
}
19+
}
20+
</script>
21+
22+
<readme>
23+
First you need to use the plugin:
24+
25+
```js
26+
import Timeago from 'vue-timeago'
27+
28+
Vue.use(Timeago)
29+
```
30+
31+
Then use the `<timeago>` component in your Vue component like this:
32+
33+
```html
34+
<template>
35+
<div>
36+
<timeago :datetime="date" />
37+
</div>
38+
</template>
39+
40+
<script>
41+
export default {
42+
data() {
43+
return {
44+
date: '2018-03-12'
45+
}
46+
}
47+
}
48+
</script>
49+
```
50+
</readme>

example/CustomConverter.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div>
3+
<div class="box" data-title="Date">
4+
<input v-model="date" type="date" />
5+
</div>
6+
<div class="box" data-title="Output" v-if="date">
7+
<timeago :datetime="date" :converter="isFutureOrPastConverter" />
8+
</div>
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
data() {
15+
return {
16+
date: '2022-01-11'
17+
}
18+
},
19+
20+
methods: {
21+
isFutureOrPastConverter(date, locale, options) {
22+
return new Date(date) > Date.now() ? 'Date is Future' : 'Date is Past'
23+
}
24+
}
25+
}
26+
</script>
27+
28+
<readme>
29+
You can use a custom converter to control how machine time is converted to human-readable time:
30+
31+
```html
32+
<template>
33+
<timeago :datetime="date" :converter="isFutureOrPastConverter" />
34+
</template>
35+
36+
<script>
37+
export default {
38+
data() {
39+
return {
40+
date: '2022-01-11'
41+
}
42+
},
43+
methods: {
44+
isFutureOrPastConverter(date) {
45+
return new Date(date) > Date.now() ? 'Date is Future' : 'Date is Past'
46+
}
47+
}
48+
}
49+
</script>
50+
```
51+
</readme>

example/index.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import './style.css'
12
import Vue from 'vue'
3+
import { create, mount } from 'demoboard'
4+
import toReact from '@egoist/vue-to-react'
25
import Timeago from '../src'
3-
import App from './app.vue'
46
import converter from '../src/converter'
7+
import BasicUsage from './BasicUsage.vue'
8+
import AutoUpdate from './AutoUpdate.vue'
9+
import CustomConverter from './CustomConverter.vue'
10+
import readme from '!raw-loader!../README.md'
511

612
const r = require.context('date-fns/locale', true, /^\.\/([\w\_]+)\/index\.js/)
713
const locales = {}
@@ -16,12 +22,23 @@ Vue.use(Timeago, {
1622
converter
1723
})
1824

19-
new Vue({
20-
el: '#app',
21-
render: h =>
22-
h(App, {
23-
props: {
24-
localeNames: Object.keys(locales)
25-
}
26-
})
25+
const demoboard = create()
26+
27+
demoboard.section('Examples').add('Basic Usage', {
28+
component: toReact(BasicUsage),
29+
readme: BasicUsage.$readme,
30+
code: BasicUsage.$code
31+
}).add('Auto Update', {
32+
component: toReact(AutoUpdate),
33+
readme: AutoUpdate.$readme,
34+
code: AutoUpdate.$code
35+
}).add('Custom Converter', {
36+
component: toReact(CustomConverter),
37+
readme: CustomConverter.$readme,
38+
code: CustomConverter.$code
39+
})
40+
41+
mount(demoboard, '#app', {
42+
title: 'Vue Timeago',
43+
readme
2744
})

example/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.box {
2+
border: 1px solid #e2e2e2;
3+
border-radius: 3px;
4+
padding: 20px;
5+
position: relative;
6+
margin-bottom: 20px;
7+
max-width: 800px;
8+
}
9+
10+
.box:before {
11+
display: block;
12+
content: attr(data-title);
13+
position: absolute;
14+
top: 0;
15+
left: 20px;
16+
transform: translateY(-50%);
17+
background: white;
18+
color: #999;
19+
padding: 0 5px;
20+
font-size: 14px;
21+
}

example/vue-readme-loader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = source => {
2+
return `export default function (Component) {
3+
Component.options.$readme = ${JSON.stringify(source.trim())}
4+
}`
5+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
"filter"
3131
],
3232
"devDependencies": {
33+
"@egoist/vue-to-react": "^1.1.0",
3334
"bili": "^4.7.0",
3435
"commitizen": "^3.0.7",
3536
"cz-conventional-changelog": "^2.1.0",
37+
"demoboard": "^0.3.1",
3638
"eslint-config-prettier": "^4.1.0",
3739
"eslint-config-rem": "^4.0.0",
3840
"eslint-plugin-prettier": "^3.0.1",
@@ -42,6 +44,7 @@
4244
"poi": "^12.5.6",
4345
"postcss-nested": "^4.1.2",
4446
"prettier": "^1.16.4",
47+
"raw-loader": "^3.0.0",
4548
"semantic-release": "^15.13.3",
4649
"vue": "^2.6.9",
4750
"vue-template-compiler": "^2.6.9",

poi.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
configureWebpack: {
3+
module: {
4+
rules: [
5+
{
6+
resourceQuery: /blockType=readme/,
7+
loader: require.resolve('./example/vue-readme-loader')
8+
}
9+
]
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)