Commit d7e9a10c authored by 尚斌杰's avatar 尚斌杰

first commit

parent 8b37bd22
name: Publish And Deploy Demo
on:
push:
tags:
- 'v*'
jobs:
build-and-deploy:
runs-on: centos
steps:
# 下载源码
- name: Checkout
uses: actions/checkout@master
# 打包构建
- name: Build
uses: actions/setup-node@master
- run: npm install
- run: npm run build
- run: tar -zcvf release.tgz .nuxt static nuxt.config.js package.json package-lock.json pm2.config.json
# 发布 Release
- name: Create Release
id: create_release
uses: actions/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
# 上传构建结果到 Release
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@master
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release.tgz
asset_name: release.tgz
asset_content_type: application/x-tgz
# 部署到服务器
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
cd /root/realworld-nuxtjs
wget https://github.com/lipengzhou/realworld-nuxtjs/releases/latest/download/release.tgz -O release.tgz
tar zxvf release.tgz
npm install --production
pm2 reload pm2.config.json
\ No newline at end of file
...@@ -16,4 +16,29 @@ export const getFeedArticles = params => { ...@@ -16,4 +16,29 @@ export const getFeedArticles = params => {
url: '/api/articles/feed', url: '/api/articles/feed',
params params
}) })
}
// 添加点赞
export const addFavorite = slug => {
return request({
method: 'POST',
url: `/api/articles/${slug}/favorite`
})
}
// 取消点赞
export const deleteFavorite = slug => {
return request({
method: 'DELETE',
url: `/api/articles/${slug}/favorite`
})
}
// 获取文章详情
export const getArticle = slug => {
return request({
method: 'GET',
url: `/api/articles/${slug}`
})
} }
\ No newline at end of file
...@@ -54,6 +54,10 @@ module.exports = { ...@@ -54,6 +54,10 @@ module.exports = {
// }) // })
} }
}, },
server:{
host: '0.0.0.0',
port: 3000
},
plugins: [ plugins: [
'~/plugins/request', '~/plugins/request',
'~/plugins/dayjs' '~/plugins/dayjs'
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "nuxt" "dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
...@@ -14,6 +16,7 @@ ...@@ -14,6 +16,7 @@
"cookieparser": "^0.1.0", "cookieparser": "^0.1.0",
"dayjs": "^1.10.4", "dayjs": "^1.10.4",
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",
"markdown-it": "^12.0.6",
"nuxt": "^2.15.4" "nuxt": "^2.15.4"
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="banner"> <div class="banner">
<div class="container"> <div class="container">
<h1>How to build webapps that scale</h1> <h1>{{ article.title }}</h1>
<div class="article-meta"> <div class="article-meta">
<a href=""><img src="http://i.imgur.com/Qr71crq.jpg" /></a> <a href=""><img src="http://i.imgur.com/Qr71crq.jpg" /></a>
...@@ -31,12 +31,7 @@ ...@@ -31,12 +31,7 @@
<div class="container page"> <div class="container page">
<div class="row article-content"> <div class="row article-content">
<div class="col-md-12"> <div class="col-md-12" v-html="article.body">
<p>
Web development technologies have evolved at an incredible clip over the past few years.
</p>
<h2 id="introducing-ionic">Introducing RealWorld.</h2>
<p>It's a great solution for learning how other frameworks work.</p>
</div> </div>
</div> </div>
...@@ -121,7 +116,18 @@ ...@@ -121,7 +116,18 @@
</div> </div>
</template> </template>
<script> <script>
import { getArticle } from '@/api/article'
import MarkdownIt from 'markdown-it'
export default { export default {
name:'Article' name:'Article',
async asyncData({ params }) {
const { data: { article } } = await getArticle(params.slug)
const md = new MarkdownIt()
article.body = md.render(article.body)
return {
article: article
}
},
} }
</script> </script>
\ No newline at end of file
...@@ -101,6 +101,8 @@ ...@@ -101,6 +101,8 @@
:class="{ :class="{
active:article.favorited active:article.favorited
}" }"
@click="onFavorite(article)"
:disabled="article.favoriteDisabled"
> >
<i class="ion-heart"></i> {{ article.favoritesCount }} <i class="ion-heart"></i> {{ article.favoritesCount }}
</button> </button>
...@@ -176,14 +178,19 @@ ...@@ -176,14 +178,19 @@
</div> </div>
</template> </template>
<script> <script>
import { getArticles, getFeedArticles } from '@/api/article' import {
getArticles,
getFeedArticles,
deleteFavorite,
addFavorite
} from '@/api/article'
import { getTags } from '@/api/tag' import { getTags } from '@/api/tag'
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
name:'Home', name:'Home',
watchQuery:['page', 'tag', 'tab'], watchQuery:['page', 'tag', 'tab'],
async asyncData({isDev, route, store, env, params, query, req, res, redirect, error}) { async asyncData({ store, query }) {
// 页面数据 // 页面数据
const page = Number.parseInt(query.page || 1) const page = Number.parseInt(query.page || 1)
...@@ -201,8 +208,14 @@ export default { ...@@ -201,8 +208,14 @@ export default {
getTags() getTags()
]) ])
const { articles, articlesCount } = articlesRes.data const {
articles,
articlesCount
} = articlesRes.data
const { tags } = tagRes.data const { tags } = tagRes.data
articles.forEach(article => article.favoriteDisabled = false)
// 标签列表 // 标签列表
return { return {
articles, articles,
...@@ -219,6 +232,23 @@ export default { ...@@ -219,6 +232,23 @@ export default {
totalPage(){ totalPage(){
return Math.ceil(this.articlesCount / this.limit) return Math.ceil(this.articlesCount / this.limit)
} }
},
methods:{
async onFavorite(article){
article.favoriteDisabled = true
if(article.favorited){
// 取消点赞
await deleteFavorite(article.slug)
article.favorited = false
article.favoritesCount -= 1
} else {
// 添加点赞
await addFavorite(article.slug)
article.favorited = true
article.favoritesCount += 1
}
article.favoriteDisabled = false
}
} }
} }
</script> </script>
......
{
"apps": [
{
"name": "RealWorld",
"script": "npm",
"args": "start"
}
]
}
\ No newline at end of file
...@@ -1691,6 +1691,11 @@ argparse@^1.0.7: ...@@ -1691,6 +1691,11 @@ argparse@^1.0.7:
dependencies: dependencies:
sprintf-js "~1.0.2" sprintf-js "~1.0.2"
argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
arr-diff@^4.0.0: arr-diff@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
...@@ -3108,6 +3113,11 @@ entities@^2.0.0: ...@@ -3108,6 +3113,11 @@ entities@^2.0.0:
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55" resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A== integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
entities@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.1.0.tgz#992d3129cf7df6870b96c57858c249a120f8b8b5"
integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==
errno@^0.1.3, errno@~0.1.7: errno@^0.1.3, errno@~0.1.7:
version "0.1.8" version "0.1.8"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.8.tgz#8bb3e9c7d463be4976ff888f76b4809ebc2e811f" resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.8.tgz#8bb3e9c7d463be4976ff888f76b4809ebc2e811f"
...@@ -4421,6 +4431,13 @@ launch-editor@^2.2.1: ...@@ -4421,6 +4431,13 @@ launch-editor@^2.2.1:
chalk "^2.3.0" chalk "^2.3.0"
shell-quote "^1.6.1" shell-quote "^1.6.1"
linkify-it@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-3.0.2.tgz#f55eeb8bc1d3ae754049e124ab3bb56d97797fb8"
integrity sha512-gDBO4aHNZS6coiZCKVhSNh43F9ioIL4JwRjLZPkoLIY4yZFwg264Y5lu2x6rb1Js42Gh6Yqm2f6L2AJcnkzinQ==
dependencies:
uc.micro "^1.0.1"
loader-runner@^2.4.0: loader-runner@^2.4.0:
version "2.4.0" version "2.4.0"
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357" resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
...@@ -4584,6 +4601,17 @@ map-visit@^1.0.0: ...@@ -4584,6 +4601,17 @@ map-visit@^1.0.0:
dependencies: dependencies:
object-visit "^1.0.0" object-visit "^1.0.0"
markdown-it@^12.0.6:
version "12.0.6"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-12.0.6.tgz#adcc8e5fe020af292ccbdf161fe84f1961516138"
integrity sha512-qv3sVLl4lMT96LLtR7xeRJX11OUFjsaD5oVat2/SNBIb21bJXwal2+SklcRbTwGwqWpWH/HRtYavOoJE+seL8w==
dependencies:
argparse "^2.0.1"
entities "~2.1.0"
linkify-it "^3.0.1"
mdurl "^1.0.1"
uc.micro "^1.0.5"
md5.js@^1.3.4: md5.js@^1.3.4:
version "1.3.5" version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
...@@ -4603,6 +4631,11 @@ mdn-data@2.0.4: ...@@ -4603,6 +4631,11 @@ mdn-data@2.0.4:
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b" resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA== integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
mem@^8.0.0: mem@^8.0.0:
version "8.1.0" version "8.1.0"
resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.0.tgz#445e47827fb757a4e5f35b0a6a62743cbfdc0a0d" resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.0.tgz#445e47827fb757a4e5f35b0a6a62743cbfdc0a0d"
...@@ -7267,6 +7300,11 @@ ua-parser-js@^0.7.26: ...@@ -7267,6 +7300,11 @@ ua-parser-js@^0.7.26:
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.28.tgz#8ba04e653f35ce210239c64661685bf9121dec31" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.28.tgz#8ba04e653f35ce210239c64661685bf9121dec31"
integrity sha512-6Gurc1n//gjp9eQNXjD9O3M/sMwVtN5S8Lv9bvOYBfKfDNiIIhqiyi01vMBO45u4zkDE420w/e0se7Vs+sIg+g== integrity sha512-6Gurc1n//gjp9eQNXjD9O3M/sMwVtN5S8Lv9bvOYBfKfDNiIIhqiyi01vMBO45u4zkDE420w/e0se7Vs+sIg+g==
uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
ufo@^0.6.10: ufo@^0.6.10:
version "0.6.11" version "0.6.11"
resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.6.11.tgz#69311ed4abc8ab671c83754b79ce0d396fea1075" resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.6.11.tgz#69311ed4abc8ab671c83754b79ce0d396fea1075"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment