├── .env.sample ├── .eslintrc ├── .gitignore ├── .nvmrc ├── .prettierignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── netlify.toml ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── scss │ │ ├── _base.scss │ │ ├── _buttons.scss │ │ ├── _core-alignment-classes.scss │ │ ├── _forms.scss │ │ ├── _layout.scss │ │ ├── _lists.scss │ │ ├── _media.scss │ │ ├── _mixins.scss │ │ ├── _tables.scss │ │ ├── _typography.scss │ │ └── _variables.scss ├── bus.js ├── components │ ├── Card.vue │ ├── Foot.vue │ ├── Loading.vue │ ├── Pagination.vue │ ├── PostBody.vue │ ├── TopBar.vue │ └── Updater.vue ├── main.js ├── mixins │ ├── ajax.js │ └── utils.js ├── router.js ├── store │ ├── index.js │ └── modules │ │ └── cache.js ├── vendor │ └── loadCSS.js └── views │ ├── Feed.vue │ ├── FourOFour.vue │ └── Post.vue └── vue.config.js /.env.sample: -------------------------------------------------------------------------------- 1 | REST_ENDPOINT="https://wptavern.com/wp-json/wp/v2" 2 | GA_TRACKING_ID="XXX" 3 | REQUEST_CACHE_MAX=150 4 | POSTS_PER_PAGE=9 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "env": { 4 | "node": true 5 | }, 6 | "extends": [ 7 | "prettier", 8 | "plugin:vue/essential", 9 | "eslint:recommended" 10 | ], 11 | "rules": { 12 | "no-undef": 0, 13 | "no-console": 0 14 | }, 15 | "parserOptions": { 16 | "parser": "babel-eslint" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | 15 | # Editor directories and files 16 | .idea 17 | .vscode 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | *.sw* 23 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v10.15.3 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | src/vendor 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '10' 4 | before_install: 5 | - npm install 6 | before_script: 7 | - npm run build 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of physical, social, cultural, or professional composition. Examples of such composition include age, ethnicity, level of development experience, race, sex, religion, and many more beyond these. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at alex@macarthur.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Set Up Local Environment 4 | 5 | 1. Clone the repository & `cd` into it. 6 | 2. Run `npm install`. 7 | 3. To spin up locally with hot reloading, execute `npm run serve`. 8 | 4. When you're ready to compile for production, run `npm run build`. 9 | 10 | ## Feature Requests / Bug Reports 11 | 12 | If you have a feature request or bug you've noticed, please [make an issue](https://github.com/alexmacarthur/wp-vue/issues) on Github, and assign the appropriate label. 13 | 14 | ## Make Pull Request 15 | 16 | To make a pull request, please follow these steps. 17 | 18 | 1. Make a descriptive issue. 19 | 2. Fork the repository. 20 | 3. Create a new branch with a brief, descriptive name. 21 | 4. Make a pull request to the master branch and note in the PR description that it closes the issue you previously created. 22 | 23 | ## THANK YOU! 24 | 25 | ... for contributing! 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alex MacArthur 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WP Vue 2 | 3 | [![Build Status](https://travis-ci.org/alexmacarthur/wp-vue.svg?branch=master)](https://travis-ci.org/alexmacarthur/wp-vue) [![Netlify Status](https://api.netlify.com/api/v1/badges/87ff7587-b7b2-4828-965c-97e606b81013/deploy-status)](https://app.netlify.com/sites/wp/deploys) 4 | 5 | This is just a simple Vue application (scaffolded using the [Vue CLI](https://cli.vuejs.org/)) that pulls posts from a WordPress REST API endpoint. Clone or fork this sucka & rip it apart to suit your own needs. If you have ideas to make it better for everyone else, contribute! 6 | 7 | ## Install 8 | 9 | In the root of the project, run `npm install`. 10 | 11 | ## Usage 12 | 13 | ### Set Your Environment Variables 14 | 15 | Various important values are loaded into the application via Node environment variables, which you'll need to define. Locally, run `cp .env.sample .env.local` to create a local file for defining the following: 16 | 17 | - `REST_ENDPOINT` - The WordPress REST API endpoint from which data will be pulled. Leave off the trailing slash. Example: `https://blah-blah-blah.com/wp-json/wp/v2` 18 | - `POSTS_PER_PAGE` - The default number of posts per page that will be displayed. 19 | - `GA_TRACKING_ID` - A Google Analytics tracking ID. 20 | - `REQUEST_CACHE_MAX` - The maximum number of AJAX requests that will be cached in memory. 21 | 22 | When deploying this on your own, you'll need to have these values set through a `.env` file you ship yourself, or if you're using something like Netlify, you can define them in your dashboard. 23 | 24 | ### Spin Up Locally 25 | 26 | Run `npm run serve` to spin up a running version from localhost. 27 | 28 | ### Build for Production 29 | 30 | Run `npm run build`. 31 | 32 | ### Deploy to Netlify 33 | 34 | Netlify is amazing, so if you're in need of somewhere to host your own version of this project, I highly recommend it. 35 | 36 | [![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/alexmacarthur/wp-vue) 37 | 38 | ## Caching 39 | 40 | Out of the box, WP Vue will locally cache AJAX requests in memory, and then load them as needed. This first happens on page load, when all queried posts on the current and adjacent pages are cached for quick access later. 41 | 42 | To keep things from getting out of control, a maximum request cache value is set. Once your cache reaches this max (regardless of how large each request is), the first request in memory will deleted as a new one is added. So, you shouldn't have to worry too much about an insane amount of data being locally stored as you move through posts. 43 | 44 | Manually reloading the page will kill this cache. It will not persist. 45 | 46 | ## Set Endpoint via URL Parameter 47 | 48 | If you'd like to share link to a version of WP Vue that uses a different endpoint than what's set via the code, you can pass that endpoint in as a URL parameter: 49 | 50 | Example: `https://wp.netlify.com?endpoint=https://css-tricks.com/wp-json/wp/v2` 51 | 52 | Instead of using the default, this will use whatever endpoint you provide in the URL. 53 | 54 | ## Contribute 55 | 56 | Please do! See the for details. 57 | 58 | ## License 59 | 60 | MIT © [Alex MacArthur](https://macarthur.me) 61 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | base = "/" 3 | publish = "/dist" 4 | command = "npm run build" 5 | 6 | [[redirects]] 7 | from = "/*" 8 | to = "/index.html" 9 | status = 200 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wp-vue", 3 | "version": "1.1.0", 4 | "author": "Alex MacArthur (https://macarthur.me)", 5 | "description": "A simple Vue blog template that displays posts from any WordPress REST API endpoint.", 6 | "scripts": { 7 | "serve": "vue-cli-service serve", 8 | "build": "vue-cli-service build", 9 | "lint": "vue-cli-service lint", 10 | "lint:fix": "eslint ./src --fix", 11 | "precommit": "pretty-quick --staged", 12 | "prettier": "prettier --write \"./src/**/*.js\"" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/alexmacarthur/wp-vue/issues" 16 | }, 17 | "keywords": [ 18 | "vue", 19 | "wordpress", 20 | "blog", 21 | "REST", 22 | "API" 23 | ], 24 | "homepage": "https://wp.netlify.com", 25 | "dependencies": { 26 | "vue": "^2.6.11", 27 | "vue-analytics": "^5.22.1", 28 | "vue-router": "^3.1.6", 29 | "vuex": "^3.1.3" 30 | }, 31 | "devDependencies": { 32 | "@vue/cli-plugin-babel": "^4.3.1", 33 | "@vue/cli-plugin-eslint": "^4.3.1", 34 | "@vue/cli-service": "^4.3.1", 35 | "babel-eslint": "^10.1.0", 36 | "eslint": "^5.16.0", 37 | "eslint-config-prettier": "^4.3.0", 38 | "eslint-plugin-vue": "^5.2.3", 39 | "husky": "^2.7.0", 40 | "node-sass": "^4.13.1", 41 | "prettier": "^1.19.1", 42 | "pretty-quick": "^1.11.1", 43 | "sass-loader": "^7.3.1", 44 | "style-resources-loader": "^1.3.3", 45 | "vue-cli-plugin-style-resources-loader": "^0.1.4", 46 | "vue-template-compiler": "^2.6.11" 47 | }, 48 | "repository": { 49 | "type": "git", 50 | "url": "https://github.com/alexmacarthur/wp-vue" 51 | }, 52 | "postcss": { 53 | "plugins": { 54 | "autoprefixer": {} 55 | } 56 | }, 57 | "browserslist": [ 58 | "> 1%", 59 | "last 2 versions", 60 | "not ie <= 8" 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexmacarthur/wp-vue/f8ceeb83f2f1a3b5929e17c05a5cac981effdc54/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | WP Vue 23 | 24 | 25 | 28 |
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 102 | 103 | 121 | -------------------------------------------------------------------------------- /src/assets/scss/_base.scss: -------------------------------------------------------------------------------- 1 | // Bitters 1.6.0 2 | // http://bitters.bourbon.io 3 | // Copyright 2013-2017 thoughtbot, inc. 4 | // MIT License 5 | 6 | @import "variables"; 7 | @import "mixins"; 8 | @import "buttons"; 9 | @import "forms"; 10 | @import "layout"; 11 | @import "lists"; 12 | @import "media"; 13 | @import "tables"; 14 | @import "typography"; 15 | -------------------------------------------------------------------------------- /src/assets/scss/_buttons.scss: -------------------------------------------------------------------------------- 1 | button, 2 | [type="submit"] { 3 | appearance: none; 4 | background-color: $action-color; 5 | border: 0; 6 | border-radius: $base-border-radius; 7 | color: #fff; 8 | cursor: pointer; 9 | display: inline-block; 10 | font-family: $base-font-family; 11 | font-size: 16px; 12 | -webkit-font-smoothing: antialiased; 13 | font-weight: 600; 14 | line-height: 1; 15 | padding: $small-spacing $base-spacing; 16 | text-align: center; 17 | text-decoration: none; 18 | transition: background-color $base-duration $base-timing; 19 | user-select: none; 20 | vertical-align: middle; 21 | white-space: nowrap; 22 | 23 | &:hover { 24 | background-color: darken($action-color, 10%); 25 | color: #fff; 26 | } 27 | 28 | &:focus { 29 | outline: $focus-outline; 30 | outline-offset: $focus-outline-offset; 31 | } 32 | 33 | &:disabled { 34 | cursor: not-allowed; 35 | opacity: 0.5; 36 | 37 | &:hover { 38 | background-color: $action-color; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/assets/scss/_core-alignment-classes.scss: -------------------------------------------------------------------------------- 1 | /* Alignment Classes from WordPress Core 2 | * https://codex.wordpress.org/CSS#WordPress_Generated_Classes 3 | -------------------------------------------------------------- */ 4 | 5 | .alignnone { 6 | margin: 5px 20px 20px 0; 7 | } 8 | 9 | .aligncenter, 10 | div.aligncenter { 11 | display: block; 12 | margin: 5px auto 5px auto; 13 | } 14 | 15 | .alignright { 16 | float:right; 17 | margin: 5px 0 20px 20px; 18 | } 19 | 20 | .alignleft { 21 | float: left; 22 | margin: 5px 20px 20px 0; 23 | } 24 | 25 | a img.alignright { 26 | float: right; 27 | margin: 5px 0 20px 20px; 28 | } 29 | 30 | a img.alignnone { 31 | margin: 5px 20px 20px 0; 32 | } 33 | 34 | a img.alignleft { 35 | float: left; 36 | margin: 5px 20px 20px 0; 37 | } 38 | 39 | a img.aligncenter { 40 | display: block; 41 | margin-left: auto; 42 | margin-right: auto; 43 | } 44 | 45 | .wp-caption { 46 | background: #fff; 47 | border: 1px solid #f0f0f0; 48 | max-width: 96%; 49 | padding: 5px 3px 10px; 50 | text-align: center; 51 | } 52 | 53 | .wp-caption.alignnone { 54 | margin: 5px 20px 20px 0; 55 | } 56 | 57 | .wp-caption.alignleft { 58 | margin: 5px 20px 20px 0; 59 | } 60 | 61 | .wp-caption.alignright { 62 | margin: 5px 0 20px 20px; 63 | } 64 | 65 | .wp-caption img { 66 | border: 0 none; 67 | height: auto; 68 | margin: 0; 69 | max-width: 98.5%; 70 | padding: 0; 71 | width: auto; 72 | } 73 | 74 | .wp-caption p.wp-caption-text { 75 | font-size: 11px; 76 | line-height: 17px; 77 | margin: 0; 78 | padding: 0 4px 5px; 79 | } 80 | 81 | .screen-reader-text { 82 | border: 0; 83 | clip: rect(1px, 1px, 1px, 1px); 84 | clip-path: inset(50%); 85 | height: 1px; 86 | margin: -1px; 87 | overflow: hidden; 88 | padding: 0; 89 | position: absolute !important; 90 | width: 1px; 91 | word-wrap: normal !important; 92 | } 93 | 94 | .screen-reader-text:focus { 95 | background-color: #eee; 96 | clip: auto !important; 97 | clip-path: none; 98 | color: #444; 99 | display: block; 100 | font-size: 1em; 101 | height: auto; 102 | left: 5px; 103 | line-height: normal; 104 | padding: 15px 23px 14px; 105 | text-decoration: none; 106 | top: 5px; 107 | width: auto; 108 | z-index: 100000; 109 | } 110 | -------------------------------------------------------------------------------- /src/assets/scss/_forms.scss: -------------------------------------------------------------------------------- 1 | $_form-box-shadow: inset 0 1px 3px rgba(#000, 0.06); 2 | $_form-box-shadow-focus: $_form-box-shadow, 0 0 5px rgba($action-color, 0.7); 3 | 4 | fieldset { 5 | background-color: transparent; 6 | border: 0; 7 | margin: 0; 8 | padding: 0; 9 | } 10 | 11 | legend { 12 | font-weight: 600; 13 | margin-bottom: $small-spacing / 2; 14 | padding: 0; 15 | } 16 | 17 | label { 18 | display: block; 19 | font-weight: 600; 20 | margin-bottom: $small-spacing / 2; 21 | } 22 | 23 | input, 24 | select, 25 | textarea { 26 | appearance: none; 27 | background-color: $base-background-color; 28 | border: $base-border; 29 | border-radius: $base-border-radius; 30 | box-shadow: $_form-box-shadow; 31 | box-sizing: border-box; 32 | margin-bottom: $small-spacing; 33 | padding: $base-spacing / 3; 34 | transition: border-color $base-duration $base-timing; 35 | width: 100%; 36 | display: block; 37 | font-family: $base-font-family; 38 | font-size: 16px; 39 | 40 | &:hover { 41 | border-color: darken($base-border-color, 20%); 42 | } 43 | 44 | &:focus { 45 | border-color: $action-color; 46 | box-shadow: $_form-box-shadow-focus; 47 | outline: none; 48 | } 49 | 50 | &:disabled { 51 | background-color: darken($base-background-color, 5%); 52 | cursor: not-allowed; 53 | 54 | &:hover { 55 | border: $base-border; 56 | } 57 | } 58 | 59 | &::placeholder { 60 | color: tint($base-font-color, 40%); 61 | } 62 | } 63 | 64 | textarea { 65 | resize: vertical; 66 | } 67 | 68 | [type="checkbox"], 69 | [type="radio"] { 70 | display: inline; 71 | margin-right: $small-spacing / 2; 72 | } 73 | 74 | [type="file"] { 75 | margin-bottom: $small-spacing; 76 | width: 100%; 77 | } 78 | 79 | select { 80 | margin-bottom: $small-spacing; 81 | width: 100%; 82 | } 83 | 84 | [type="checkbox"], 85 | [type="radio"], 86 | [type="file"], 87 | select { 88 | &:focus { 89 | outline: $focus-outline; 90 | outline-offset: $focus-outline-offset; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/assets/scss/_layout.scss: -------------------------------------------------------------------------------- 1 | html { 2 | box-sizing: border-box; 3 | font-size: 62.5%; 4 | } 5 | 6 | *, 7 | *::before, 8 | *::after { 9 | box-sizing: inherit; 10 | } 11 | 12 | html, 13 | body { 14 | height: 100%; 15 | } 16 | 17 | body { 18 | margin: 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/assets/scss/_lists.scss: -------------------------------------------------------------------------------- 1 | ul, 2 | ol { 3 | list-style-type: none; 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | dl { 9 | margin: 0; 10 | } 11 | 12 | dt { 13 | font-weight: 600; 14 | margin: 0; 15 | } 16 | 17 | dd { 18 | margin: 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/assets/scss/_media.scss: -------------------------------------------------------------------------------- 1 | figure { 2 | margin: 0; 3 | } 4 | 5 | img, 6 | picture { 7 | margin: 0; 8 | max-width: 100%; 9 | } 10 | -------------------------------------------------------------------------------- /src/assets/scss/_mixins.scss: -------------------------------------------------------------------------------- 1 | $large: 1200px; 2 | $medium: 1024px; 3 | $small: 992px; 4 | $mobile: 600px; 5 | $tiny: 400px; 6 | 7 | @mixin media ($breakpoint) { 8 | @media screen and (min-width: $breakpoint) { 9 | @content; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/assets/scss/_tables.scss: -------------------------------------------------------------------------------- 1 | table { 2 | border-collapse: collapse; 3 | margin: $base-spacing 0; 4 | table-layout: fixed; 5 | text-align: left; 6 | width: 100%; 7 | } 8 | 9 | thead { 10 | line-height: $heading-line-height; 11 | vertical-align: bottom; 12 | } 13 | 14 | tbody { 15 | vertical-align: top; 16 | } 17 | 18 | tr { 19 | border-bottom: $base-border; 20 | } 21 | 22 | th { 23 | font-weight: 600; 24 | } 25 | 26 | th, 27 | td { 28 | padding: $small-spacing $small-spacing $small-spacing 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/assets/scss/_typography.scss: -------------------------------------------------------------------------------- 1 | html { 2 | color: $base-font-color; 3 | font-family: $base-font-family; 4 | font-size: 100%; 5 | line-height: $base-line-height; 6 | } 7 | 8 | h1, 9 | h2, 10 | h3, 11 | h4, 12 | h5, 13 | h6 { 14 | font-family: $heading-font-family; 15 | font-size: $medium-font-size; 16 | font-weight: normal; 17 | line-height: $heading-line-height; 18 | margin: $small-spacing 0; 19 | 20 | a { 21 | color: inherit; 22 | 23 | &:hover { 24 | color: $action-color; 25 | } 26 | } 27 | } 28 | 29 | h1 { 30 | font-size: $header-font-size; 31 | font-weight: 100; 32 | } 33 | 34 | p { 35 | margin: 0 0 $small-spacing; 36 | font-size: $base-font-size; 37 | } 38 | 39 | a { 40 | color: $action-color; 41 | text-decoration: none; 42 | transition: color $base-duration $base-timing; 43 | cursor: pointer; 44 | 45 | &:hover { 46 | color: darken($action-color, 25%); 47 | } 48 | 49 | &:focus { 50 | outline: none 51 | } 52 | 53 | &.is-disabled { 54 | pointer-events: none; 55 | opacity: .5; 56 | } 57 | } 58 | 59 | hr { 60 | border-bottom: $base-border; 61 | border-left: 0; 62 | border-right: 0; 63 | border-top: 0; 64 | margin: $base-spacing 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/assets/scss/_variables.scss: -------------------------------------------------------------------------------- 1 | // Typography 2 | $heading-font-family: 'Nunito', sans-serif; 3 | $base-font-family: 'Open Sans', sans-serif; 4 | 5 | // Line height 6 | $base-line-height: 1.5; 7 | $heading-line-height: 1.2; 8 | 9 | // Font sizes 10 | $header-font-size: 2rem; 11 | $medium-font-size: 1.5rem; 12 | $base-font-size: 1rem; 13 | $small-font-size: .75rem; 14 | 15 | // Other Sizes 16 | $base-border-radius: 3px; 17 | $base-spacing: $base-line-height * 1em; 18 | $small-spacing: $base-spacing / 2; 19 | 20 | // Colors 21 | $white: #ffffff; 22 | $blue: #1565c0; 23 | $gray: #333; 24 | $gray--medium: #999; 25 | $gray--mediumLight: lighten($gray--medium, 25%); 26 | $gray--light: #fafafa; 27 | $salmon: #E56B70; 28 | 29 | // Font Colors 30 | $base-font-color: $gray; 31 | $action-color: $salmon; 32 | 33 | // Border 34 | $base-border-color: $gray--light; 35 | $base-border: 1px solid $base-border-color; 36 | 37 | // Background Colors 38 | $base-background-color: #fff; 39 | 40 | // Focus 41 | $focus-outline-color: transparentize($action-color, 0.4); 42 | $focus-outline-width: 3px; 43 | $focus-outline: $focus-outline-width solid $focus-outline-color; 44 | $focus-outline-offset: 2px; 45 | 46 | // Animations 47 | $base-duration: 150ms; 48 | $base-timing: ease; 49 | -------------------------------------------------------------------------------- /src/bus.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | export default new Vue(); 3 | -------------------------------------------------------------------------------- /src/components/Card.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 39 | 40 | 85 | 86 | -------------------------------------------------------------------------------- /src/components/Foot.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 26 | -------------------------------------------------------------------------------- /src/components/Loading.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 36 | 37 | 58 | -------------------------------------------------------------------------------- /src/components/Pagination.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 42 | 43 | 65 | -------------------------------------------------------------------------------- /src/components/PostBody.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 17 | 18 | 45 | -------------------------------------------------------------------------------- /src/components/TopBar.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 54 | 55 | 106 | -------------------------------------------------------------------------------- /src/components/Updater.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 62 | 63 | 107 | 108 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import VueAnalytics from "vue-analytics"; 3 | import App from "./App.vue"; 4 | import router from "./router"; 5 | import utils from "./mixins/utils"; 6 | import store from "./store"; 7 | 8 | Vue.mixin(utils); 9 | 10 | //-- Initialize Google Analytics tracking. 11 | Vue.use(VueAnalytics, { 12 | id: GA_TRACKING_ID, 13 | router 14 | }); 15 | 16 | new Vue({ 17 | el: "#app", 18 | router, 19 | store, 20 | render: h => h(App) 21 | }).$mount("#app"); 22 | -------------------------------------------------------------------------------- /src/mixins/ajax.js: -------------------------------------------------------------------------------- 1 | export default { 2 | methods: { 3 | /** 4 | * Get response from memory, if it exists. Otherwise, AJAX. 5 | * 6 | * @param {string} path The endpoint 7 | * @return {Promise} 8 | */ 9 | get: function(path) { 10 | return new Promise(async (resolve, reject) => { 11 | let response, data; 12 | 13 | if (this.$store.state.cache.requests[path] !== undefined) { 14 | return resolve(this.$store.state.cache.requests[path]); 15 | } 16 | 17 | try { 18 | response = await fetch(this.$store.state.endpoint + path, { 19 | method: "GET" 20 | }); 21 | 22 | data = { 23 | data: await response.json(), 24 | headers: { 25 | "x-wp-total": response.headers.get("x-wp-total"), 26 | "x-wp-totalpages": response.headers.get("x-wp-totalpages") 27 | } 28 | }; 29 | } catch (error) { 30 | return reject(error); 31 | } 32 | 33 | this.$store.commit("cache/saveRequest", { 34 | path, 35 | data: data 36 | }); 37 | 38 | //-- Generate mock requests for later use on individual posts. 39 | //-- Mimics structure of response if it were authentic. 40 | if (path.startsWith("/posts") && !path.includes("slug")) { 41 | data.data.forEach(post => { 42 | this.$store.commit("cache/saveRequest", { 43 | path: `/posts?slug=${post.slug}`, 44 | data: { 45 | data: [post] 46 | } 47 | }); 48 | }); 49 | } 50 | 51 | return resolve(data); 52 | }); 53 | } 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /src/mixins/utils.js: -------------------------------------------------------------------------------- 1 | export default { 2 | data() { 3 | return { 4 | months: [ 5 | "January", 6 | "February", 7 | "March", 8 | "April", 9 | "May", 10 | "June", 11 | "July", 12 | "August", 13 | "September", 14 | "October", 15 | "November", 16 | "December" 17 | ] 18 | }; 19 | }, 20 | 21 | methods: { 22 | getFormattedDate: function(time) { 23 | let date = new Date(time); 24 | return `${ 25 | this.months[date.getMonth()] 26 | } ${date.getDate()}, ${date.getFullYear()}`; 27 | }, 28 | 29 | goBack: function() { 30 | this.$router.go(-1); 31 | }, 32 | 33 | getQueryString: function(name) { 34 | const urlParams = new URLSearchParams(window.location.search); 35 | return urlParams.get(name); 36 | } 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import VueRouter from "vue-router"; 3 | import Feed from "./views/Feed"; 4 | import FourOFour from "./views/FourOFour"; 5 | import Post from "./views/Post"; 6 | import bus from "./bus"; 7 | 8 | Vue.use(VueRouter); 9 | 10 | const routes = [ 11 | { 12 | name: "home", 13 | path: "/", 14 | redirect: "/posts" 15 | }, 16 | { 17 | name: "posts", 18 | path: "/posts", 19 | component: Feed 20 | }, 21 | { 22 | name: "post", 23 | path: "/posts/:slug", 24 | component: Post 25 | }, 26 | { 27 | name: "page", 28 | path: "/page/:page", 29 | component: Feed 30 | }, 31 | { 32 | name: "four-o-four", 33 | path: "/404", 34 | component: FourOFour 35 | }, 36 | { 37 | path: "*", 38 | redirect: "/404" 39 | } 40 | ]; 41 | 42 | const router = new VueRouter({ 43 | mode: "history", 44 | routes 45 | }); 46 | 47 | router.afterEach(() => { 48 | //-- Bump the key on App component to force component to update on route change. 49 | bus.$emit("bumpViewKey"); 50 | }); 51 | 52 | export default router; 53 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Vuex from "vuex"; 3 | import cache from "./modules/cache"; 4 | import bus from "../bus"; 5 | 6 | Vue.use(Vuex); 7 | 8 | export default new Vuex.Store({ 9 | state: { 10 | endpoint: REST_ENDPOINT 11 | }, 12 | 13 | mutations: { 14 | updateEndpoint(state, endpoint) { 15 | state.endpoint = endpoint; 16 | bus.$emit("clearError"); 17 | bus.$emit("bumpViewKey", "Updating content..."); 18 | } 19 | }, 20 | 21 | modules: { 22 | cache 23 | } 24 | }); 25 | -------------------------------------------------------------------------------- /src/store/modules/cache.js: -------------------------------------------------------------------------------- 1 | export default { 2 | namespaced: true, 3 | 4 | state: { 5 | requests: {} 6 | }, 7 | 8 | mutations: { 9 | saveRequest(state, payload) { 10 | //-- If the request max has been hit, remove the first one. 11 | if (Object.keys(state.requests).length >= REQUEST_CACHE_MAX) { 12 | delete state.requests[Object.keys(state.requests)[0]]; 13 | } 14 | 15 | state.requests[payload.path] = payload.data; 16 | }, 17 | 18 | wipe(state) { 19 | state.requests = {}; 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /src/vendor/loadCSS.js: -------------------------------------------------------------------------------- 1 | /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */ 2 | !function(e){"use strict";var n=function(n,t,o){function i(e){if(a.body)return e();setTimeout(function(){i(e)})}function r(){l.addEventListener&&l.removeEventListener("load",r),l.media=o||"all"}var d,a=e.document,l=a.createElement("link");if(t)d=t;else{var f=(a.body||a.getElementsByTagName("head")[0]).childNodes;d=f[f.length-1]}var s=a.styleSheets;l.rel="stylesheet",l.href=n,l.media="only x",i(function(){d.parentNode.insertBefore(l,t?d:d.nextSibling)});var u=function(e){for(var n=l.href,t=s.length;t--;)if(s[t].href===n)return e();setTimeout(function(){u(e)})};return l.addEventListener&&l.addEventListener("load",r),l.onloadcssdefined=u,u(r),l};"undefined"!=typeof exports?exports.loadCSS=n:e.loadCSS=n}("undefined"!=typeof global?global:this); 3 | 4 | /*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */ 5 | !function(t){if(t.loadCSS){var e=loadCSS.relpreload={};if(e.support=function(){try{return t.document.createElement("link").relList.supports("preload")}catch(t){return!1}},e.poly=function(){for(var e=t.document.getElementsByTagName("link"),r=0;r 2 |
3 | 4 |
5 |

6 | WP Vue is a simple template built with Vue JS that displays posts from a WordPress REST API endpoint. 7 | Take what you see here & rip it apart to suit your needs. To improve it for everyone else, contribute on Github. 8 |

9 |
10 | 11 |
    12 | 17 |
18 | 19 | 23 | 24 |
25 | 26 | 27 | 142 | 143 | 157 | 158 | -------------------------------------------------------------------------------- /src/views/FourOFour.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 29 | 30 | 39 | -------------------------------------------------------------------------------- /src/views/Post.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | 106 | 107 | 163 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require("webpack"); 2 | const path = require("path"); 3 | 4 | const CONSTANTS = { 5 | POSTS_PER_PAGE: JSON.stringify(process.env.POSTS_PER_PAGE), 6 | REQUEST_CACHE_MAX: JSON.stringify(process.env.REQUEST_CACHE_MAX), 7 | REST_ENDPOINT: JSON.stringify(process.env.REST_ENDPOINT), 8 | GA_TRACKING_ID: JSON.stringify(process.env.GA_TRACKING_ID) 9 | }; 10 | 11 | module.exports = { 12 | pluginOptions: { 13 | "style-resources-loader": { 14 | preProcessor: "scss", 15 | patterns: [ 16 | path.resolve(__dirname, "./src/assets/scss/_variables.scss"), 17 | path.resolve(__dirname, "./src/assets/scss/_mixins.scss") 18 | ] 19 | } 20 | }, 21 | configureWebpack: { 22 | plugins: [new webpack.DefinePlugin(CONSTANTS)] 23 | } 24 | }; 25 | --------------------------------------------------------------------------------