├── src ├── assets │ ├── js │ │ └── main.js │ └── css │ │ └── main.css ├── plugins │ ├── adsense.js │ └── currency.js ├── data │ └── config.js ├── pages │ ├── about.vue │ ├── index.vue │ └── post │ │ └── _slug.vue ├── layouts │ └── default.vue ├── mixins │ └── post-mixin.js ├── components │ ├── pagination.vue │ ├── footer-section.vue │ ├── card-post.vue │ └── header-section.vue └── store │ └── index.js ├── .babelrc ├── .editorconfig ├── gh-publish.js ├── README.md ├── nuxt.config.js ├── LICENSE ├── .gitignore └── package.json /src/assets/js/main.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env" 4 | ], 5 | "plugins": [ 6 | "transform-runtime", 7 | "transform-object-rest-spread" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true -------------------------------------------------------------------------------- /gh-publish.js: -------------------------------------------------------------------------------- 1 | var ghpages = require('gh-pages'); 2 | var path = require('path'); 3 | 4 | ghpages.publish('dist', function(err) { 5 | console.log('done publishing to gh-pages', err) 6 | }); -------------------------------------------------------------------------------- /src/plugins/adsense.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Ads from 'vue-google-adsense' 3 | 4 | Vue.use(require('vue-script2')) 5 | 6 | Vue.use(Ads.Adsense) 7 | Vue.use(Ads.InArticleAdsense) 8 | Vue.use(Ads.InFeedAdsense) 9 | -------------------------------------------------------------------------------- /src/data/config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | api: { 3 | base: 'https://mazipanneh.com/blog/wp-json', 4 | posts: '/wp/v2/posts' 5 | }, 6 | getApiPath: function (keyApi) { 7 | return this.api.base + this.api[keyApi] 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /src/plugins/currency.js: -------------------------------------------------------------------------------- 1 | import VueCurrencyFilter from 'vue-currency-filter' 2 | import Vue from 'vue' 3 | Vue.use(VueCurrencyFilter, { 4 | symbol: '$', 5 | thousandsSeparator: '.', 6 | fractionCount: 2, 7 | fractionSeparator: ',', 8 | symbolPosition: 'front', 9 | symbolSpacing: true 10 | }) 11 | -------------------------------------------------------------------------------- /src/assets/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #eee; 3 | font-family: -apple-system,BlinkMacSystemFont,"Source Sans Pro",Roboto,'Helvetica Neue',Arial,sans-serif; 4 | } 5 | .content { 6 | margin-top: 100px; 7 | } 8 | .nav-tag{ 9 | padding-right: 30px; 10 | } 11 | .navbar-burger{ 12 | border: 0; 13 | } -------------------------------------------------------------------------------- /src/pages/about.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuxt-blog 2 | :memo: Personal blog built with Nuxt.js and wordpress rest api 3 | 4 | ## Nuxt.js Build Setup 5 | 6 | ``` bash 7 | # install dependencies 8 | $ npm install # Or yarn install 9 | 10 | # serve with hot reload at localhost:3000 11 | $ npm run dev 12 | 13 | # build for production and launch server 14 | $ npm run build 15 | $ npm start 16 | 17 | # generate static project 18 | $ npm run generate 19 | 20 | # publish to gh-pages 21 | $ npm run publish 22 | ``` 23 | 24 | For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js). 25 | 26 | ## Wordpress Rest API 27 | 28 | For Wordpress Rest API explanation, see the docs [https://developer.wordpress.org/rest-api/](https://developer.wordpress.org/rest-api/) 29 | -------------------------------------------------------------------------------- /src/layouts/default.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 35 | 36 | 39 | -------------------------------------------------------------------------------- /src/mixins/post-mixin.js: -------------------------------------------------------------------------------- 1 | export default { 2 | methods: { 3 | subStringDate: function(dateStr) { 4 | return dateStr.substring(10, 0) 5 | }, 6 | getFeatureImage: function(contentStr) { 7 | let styleImg = { 8 | backgroundImage: 'url(https://bulma.io/images/placeholders/96x96.png)' 9 | } 10 | let validExt = ['.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG'] 11 | 12 | try { 13 | let allSrc = contentStr.match(/src=(.*)/g)[0].split(' ') 14 | let img = allSrc[0].replace('src="', '').replace('"', '') 15 | 16 | let isValidExt = validExt.some(str => img.includes(str)) 17 | if (isValidExt) { 18 | styleImg = { 19 | backgroundImage: 'url(' + img + ')' 20 | } 21 | } 22 | } catch (error) { 23 | console.log('error get feature image ', error) 24 | } 25 | 26 | return styleImg 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | head: { 3 | title: 'nuxt-blog', 4 | description: 'Personal Blog with Nuxt.js', 5 | meta: [ 6 | { charset: 'utf-8' }, 7 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 8 | { hid: 'description', name: 'description', content: 'Personal Blog with Nuxt.js' } 9 | ], 10 | link: [ 11 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 12 | ] 13 | }, 14 | srcDir: 'src/', 15 | build: { 16 | vendor: ['axios'], 17 | postcss: { 18 | plugins: { 19 | 'postcss-custom-properties': false 20 | } 21 | } 22 | }, 23 | loading: { color: 'cyan' }, 24 | router: { 25 | base: '/nuxt-blog/' 26 | }, 27 | css: [ 28 | 'bulma', 29 | '@/assets/css/main.css' 30 | ], 31 | plugins: [ 32 | { src: '~/plugins/currency.js', ssr: false } 33 | ], 34 | render: { 35 | bundleRenderer: { 36 | shouldPreload: (file, type) => { 37 | return ['script', 'style', 'font'].includes(type) 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Irfan Maulana 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. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # Nuxt build 61 | .nuxt 62 | 63 | # Nuxt generate 64 | dist -------------------------------------------------------------------------------- /src/pages/index.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 49 | 50 | 55 | -------------------------------------------------------------------------------- /src/components/pagination.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt-blog", 3 | "description": "Personal Blog with Nuxt.js", 4 | "version": "1.0.0-beta", 5 | "license": "MIT", 6 | "author": "Irfan Maulana (https://github.com/mazipan/)", 7 | "private": false, 8 | "main": "https://github.com/mazipan/nuxt-blog", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/mazipan/nuxt-blog.git" 12 | }, 13 | "scripts": { 14 | "dev": "nuxt", 15 | "build": "./node_modules/.bin/nuxt build", 16 | "start": "./node_modules/.bin/nuxt start", 17 | "lint": "./node_modules/.bin/eslint --ext .js,.vue pages layout --color", 18 | "generate": "./node_modules/.bin/nuxt generate", 19 | "buildgenerate": "npm run build && npm run generate", 20 | "dist": "npm run lint && npm run generate", 21 | "publish": "node ./gh-publish.js" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "eslint:recommended", 26 | "plugin:vue/recommended" 27 | ] 28 | }, 29 | "eslintIgnore": [ 30 | ".nuxt/*.js", 31 | "assets/*.js", 32 | "data/*.js", 33 | "dist", 34 | "node_modules" 35 | ], 36 | "dependencies": {}, 37 | "devDependencies": { 38 | "axios": "^0.18.0", 39 | "babel-core": "^6.26.0", 40 | "babel-loader": "^7.1.4", 41 | "babel-preset-env": "^1.6.1", 42 | "babel-plugin-transform-runtime": "^6.23.0", 43 | "babel-plugin-transform-object-rest-spread": "6.26.0", 44 | "bulma": "^0.6.2", 45 | "eslint": "^4.19.1", 46 | "eslint-plugin-vue": "4.4.0", 47 | "gh-pages": "1.1.0", 48 | "node-sass": "^4.8.3", 49 | "nuxt": "^1.4.0", 50 | "sass-loader": "^6.0.7", 51 | "vue-i18n": "^7.6.0", 52 | "vue-currency-filter": "2.1.1", 53 | "vue-google-adsense": "1.0.4", 54 | "vue-script2": "2.0.1", 55 | "vuex": "3.0.1" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/components/footer-section.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | 52 | 53 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vuex from 'vuex' 2 | import axios from 'axios' 3 | import config from '@/data/config' 4 | 5 | const createStore = () => { 6 | return new Vuex.Store({ 7 | state: { 8 | blogTitle: 'Irfan Maulana', 9 | blogDesc: 'Pelajari, Tulis, Kemudian Bagikan', 10 | posts: [], 11 | post: {} 12 | }, 13 | getters: { 14 | blogTitle(state) { 15 | return state.blogTitle 16 | }, 17 | blogDesc(state) { 18 | return state.blogDesc 19 | }, 20 | posts(state) { 21 | return state.posts 22 | }, 23 | post(state) { 24 | return state.post 25 | } 26 | }, 27 | mutations: { 28 | setBlogTitle(state, data) { 29 | state.blogTitle = data 30 | }, 31 | setBlogDesc(state, data) { 32 | state.blogDesc = data 33 | }, 34 | setPosts(state, data) { 35 | state.posts = data 36 | }, 37 | setPost(state, data) { 38 | state.post = data 39 | } 40 | }, 41 | actions: { 42 | getBlogData({commit}) { 43 | axios 44 | .get(config.api.base) 45 | .then(function(response) { 46 | console.log('success getting blog data : ', response.data) 47 | commit('setBlogTitle', response.data.name) 48 | commit('setBlogDesc', response.data.description) 49 | }) 50 | .catch(function(error) { 51 | console.log('error getting blog desc : ', error) 52 | }) 53 | }, 54 | getPosts({commit}) { 55 | axios 56 | .get(config.getApiPath('posts') + '?per_page=9') 57 | .then(function(response) { 58 | console.log('success getting posts : ', response.data) 59 | commit('setPosts', response.data) 60 | }) 61 | .catch(function(error) { 62 | console.log('error getting posts : ', error) 63 | }) 64 | }, 65 | getPostByParam({commit}, data) { 66 | const params = { 67 | page: 1, 68 | per_page: 1, 69 | ...data 70 | } 71 | 72 | axios 73 | .get(config.getApiPath('posts') + '?per_page=1&page=1', {params}) 74 | .then(function(response) { 75 | console.log('success getting post : ', response.data) 76 | commit('setPost', response.data) 77 | }) 78 | .catch(function(error) { 79 | console.log('error getting post : ', error) 80 | }) 81 | } 82 | } 83 | }) 84 | } 85 | 86 | export default createStore 87 | -------------------------------------------------------------------------------- /src/components/card-post.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | 57 | 58 | -------------------------------------------------------------------------------- /src/components/header-section.vue: -------------------------------------------------------------------------------- 1 | 68 | 69 | 76 | 77 | -------------------------------------------------------------------------------- /src/pages/post/_slug.vue: -------------------------------------------------------------------------------- 1 | 57 | 58 | 81 | 82 | --------------------------------------------------------------------------------