├── .editorconfig
├── .gitignore
├── .travis.yml
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
└── index.html
├── src
├── App.vue
├── assets
│ └── logo.png
├── components
│ ├── Homepage.vue
│ └── Navbar.vue
├── main.js
├── router.js
├── store
│ ├── actions.js
│ ├── index.js
│ └── mutations.js
└── views
│ ├── About.vue
│ ├── Home.vue
│ ├── Item.vue
│ ├── New.vue
│ └── Single.vue
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "10"
5 |
6 | before_script:
7 | - npm install
8 |
9 | script:
10 | - npm run build
11 |
12 | # deploy:
13 | # provider: s3
14 | # access_key_id:
15 | # secret_access_key:
16 | # secure:
17 | # bucket: my-bucket-name
18 | # local-dir: dist
19 | # skip_cleanup: true
20 | # region: eu-west-1
21 | # acl: public_read
22 | # on:
23 | # repo: elliotforbes/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # hn-clone
2 |
3 | ## Project setup
4 | ```
5 | yarn install
6 | ```
7 |
8 | ### Compiles and hot-reloads for development
9 | ```
10 | yarn run serve
11 | ```
12 |
13 | ### Compiles and minifies for production
14 | ```
15 | yarn run build
16 | ```
17 |
18 | ### Run your tests
19 | ```
20 | yarn run test
21 | ```
22 |
23 | ### Lints and fixes files
24 | ```
25 | yarn run lint
26 | ```
27 |
28 | ### Customize configuration
29 | See [Configuration Reference](https://cli.vuejs.org/config/).
30 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hn-clone",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build",
8 | "lint": "vue-cli-service lint"
9 | },
10 | "dependencies": {
11 | "axios": "^0.18.0",
12 | "vue": "^2.5.22",
13 | "vue-router": "^3.0.1",
14 | "vuex": "^3.1.0"
15 | },
16 | "devDependencies": {
17 | "@vue/cli-plugin-babel": "^3.4.0",
18 | "@vue/cli-plugin-eslint": "^3.4.0",
19 | "@vue/cli-service": "^3.4.0",
20 | "babel-eslint": "^10.0.1",
21 | "eslint": "^5.8.0",
22 | "eslint-plugin-vue": "^5.0.0",
23 | "vue-template-compiler": "^2.5.21"
24 | },
25 | "eslintConfig": {
26 | "root": true,
27 | "env": {
28 | "node": true
29 | },
30 | "extends": [
31 | "plugin:vue/essential",
32 | "eslint:recommended"
33 | ],
34 | "rules": {},
35 | "parserOptions": {
36 | "parser": "babel-eslint"
37 | }
38 | },
39 | "postcss": {
40 | "plugins": {
41 | "autoprefixer": {}
42 | }
43 | },
44 | "browserslist": [
45 | "> 1%",
46 | "last 2 versions",
47 | "not ie <= 8"
48 | ]
49 | }
50 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elliotforbes/hackernews-vuejs/888447828a58251ecd514cdc014245099c69103f/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | hn-clone
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
17 |
18 |
48 |
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elliotforbes/hackernews-vuejs/888447828a58251ecd514cdc014245099c69103f/src/assets/logo.png
--------------------------------------------------------------------------------
/src/components/Homepage.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Homepage
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/src/components/Navbar.vue:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App.vue'
3 | import store from './store/index.js'
4 | import router from './router'
5 |
6 | Vue.config.productionTip = false
7 |
8 | new Vue({
9 | router,
10 | store: store,
11 | render: h => h(App)
12 | }).$mount('#app')
13 |
--------------------------------------------------------------------------------
/src/router.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 | import Home from './views/Home.vue'
4 | import Single from './views/Single.vue'
5 | import New from './views/New.vue'
6 |
7 | Vue.use(Router)
8 |
9 | export default new Router({
10 | mode: 'history',
11 | base: process.env.BASE_URL,
12 | routes: [
13 | {
14 | path: '/',
15 | name: 'home',
16 | component: Home
17 | },
18 | {
19 | path: '/story/:id',
20 | name: 'Single',
21 | component: Single,
22 | },
23 | {
24 | path: '/new',
25 | name: 'New',
26 | component: New,
27 | },
28 | ]
29 | })
30 |
--------------------------------------------------------------------------------
/src/store/actions.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 |
3 | export default {
4 | fetch_top_stories: ({ commit }) => {
5 | axios.get('https://hacker-news.firebaseio.com/v0/topstories.json')
6 | .then(resp => {
7 | let results = resp.data.slice(0, 25)
8 | results.forEach(element => {
9 | axios.get('https://hacker-news.firebaseio.com/v0/item/' + element + '.json')
10 | .then((result) => {
11 | commit('APPEND_TOP_STORY', result)
12 | })
13 | .catch((err) => {
14 | /* eslint-disable */
15 | console.log(err)
16 | })
17 | })
18 | })
19 | .catch(err => {
20 | /* eslint-disable */
21 | console.log(err)
22 | })
23 | },
24 | fetch_new_stories: ({ commit }) => {
25 | axios.get('https://hacker-news.firebaseio.com/v0/newstories.json')
26 | .then(resp => {
27 | let results = resp.data.slice(0, 25)
28 | results.forEach(element => {
29 | axios.get('https://hacker-news.firebaseio.com/v0/item/' + element + '.json')
30 | .then((result) => {
31 | commit('APPEND_NEW_STORY', result)
32 | })
33 | .catch((err) => {
34 | console.log(err)
35 | })
36 | })
37 | })
38 | .catch(err => {
39 | /* eslint-disable */
40 | console.log(err)
41 | })
42 | }
43 | }
--------------------------------------------------------------------------------
/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vuex from 'vuex'
2 | import Vue from 'vue'
3 | import actions from './actions.js'
4 | import mutations from './mutations.js'
5 |
6 | Vue.use(Vuex)
7 |
8 | export default new Vuex.Store({
9 | state: {
10 | topStories: [],
11 | newStories: []
12 | },
13 | mutations,
14 | actions
15 | })
--------------------------------------------------------------------------------
/src/store/mutations.js:
--------------------------------------------------------------------------------
1 | export default {
2 | APPEND_TOP_STORY: (state, article) => {
3 | state.topStories.push(article)
4 | },
5 | APPEND_NEW_STORY: (state, article) => {
6 | state.newStories.push(article)
7 | }
8 | }
--------------------------------------------------------------------------------
/src/views/About.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
This is an about page
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/views/Home.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
26 |
--------------------------------------------------------------------------------
/src/views/Item.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{ story.data.score }}
4 | {{ story.data.title }}{{ story.data.url | host }}
5 |
6 | by {{ story.data.by }} | {{ story.data.time }} Ago | {{ story.data.descendants }} comments
7 |
8 |
9 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/src/views/New.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
26 |
--------------------------------------------------------------------------------
/src/views/Single.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{ story.title }}
4 |
Score: {{ story.score }}
5 |
{{ story.url }}
6 |
7 |
16 |
17 |
18 |
19 |
20 |
21 |
56 |
57 |
--------------------------------------------------------------------------------
{{ comment.text }}
10 |