Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration to nuxt3 #96

Merged
merged 53 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f3bf00e
feat: init migration to nuxt3
antfu Apr 18, 2022
207ae33
chore: update
antfu Apr 19, 2022
13254f4
chore: update
antfu Apr 19, 2022
6fa168d
chore: switch to nuxt eslint config
antfu Apr 19, 2022
ecca97d
chore: update ignore
antfu Apr 19, 2022
f7e4719
chore: update
antfu Apr 19, 2022
e160b93
chore: lint
antfu Apr 19, 2022
3a60a07
chore: cleanup
antfu Apr 19, 2022
8f05323
chore: clean up
antfu Apr 19, 2022
26bd583
chore: netlify config
antfu Apr 19, 2022
80e24e4
Update layouts/default.vue
antfu Apr 19, 2022
4b860a7
fix: avoid using `abortNavigation` for now
antfu Apr 19, 2022
53f013e
chore: cleanup
antfu Apr 19, 2022
85a225f
chore: migrate to `nuxt` package
antfu Apr 20, 2022
626f7d5
chore: cleanup
antfu Apr 20, 2022
fdd6c2c
chore: update docs
antfu Apr 20, 2022
176da43
chore: remove stylus
antfu Apr 20, 2022
6e46ed2
chore: update readme
antfu Apr 20, 2022
6a2c10d
Merge branch 'master' into nuxt3
antfu Apr 20, 2022
ee00722
chore: update
antfu Apr 20, 2022
9880e8a
chore: merge
antfu Apr 20, 2022
0035923
chore: update styling
antfu Apr 20, 2022
8b38d4d
chore: styling
antfu Apr 20, 2022
c760b74
chore: update
antfu Apr 21, 2022
d6f7753
feat: server api
antfu Apr 21, 2022
52414b1
feat: use server api
antfu Apr 21, 2022
e194283
fix: await for fetching on server side
antfu Apr 21, 2022
028dc26
chore: update spinner
antfu Apr 21, 2022
e7e33eb
refactor: clean up
antfu Apr 21, 2022
1593703
chore: move to dep deps
antfu Apr 21, 2022
dbd1fc8
chore: try workaround 404
antfu Apr 21, 2022
b9ed80d
chore: cleanup
antfu Apr 26, 2022
38eabb9
chore: update deps
antfu Apr 26, 2022
6f386ff
chore: remove deps on pinia
antfu Apr 27, 2022
249eb10
chore: use Pascal case
antfu Apr 27, 2022
6f5d6f3
chore: update lock
antfu Apr 27, 2022
18dde9a
chore: update
antfu Apr 27, 2022
f703758
chore: update
antfu Apr 27, 2022
2f66c98
fix: 404
antfu Apr 28, 2022
05dd671
chore: update performance
antfu Apr 28, 2022
013f7a1
chore: update deps
antfu May 8, 2022
c5f4bb8
chore: style
antfu May 9, 2022
dd13623
chore: update
antfu May 9, 2022
411e5ce
chore: fix lazyload on server side
antfu May 9, 2022
6de3e05
chore: remove transition
antfu May 9, 2022
a5fa7e3
feat: rework client fetch
antfu May 9, 2022
fb80ccb
chore: improve
antfu May 9, 2022
7e22ba7
chore: type
antfu May 11, 2022
83a4893
chore: use NuxtLink
antfu May 17, 2022
b586fb9
chore: update ogimage
antfu May 18, 2022
78c0257
chore: improve SEO
antfu May 18, 2022
7fd2b8b
Apply suggestions from code review
atinux May 24, 2022
b2548be
Update README.md
atinux May 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@nuxtjs/eslint-config-typescript",
"rules": {
"vue/no-v-html": "off",
"vue/no-multiple-template-root": "off"
}
}
5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package-lock.json
*.iml
.nuxt
.vscode
.output

static/manifest*.json
static/sw.js
static/workbox-sw*.js*
public/manifest*.json
public/sw.js
public/workbox-sw*.js*
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
3 changes: 0 additions & 3 deletions .vercelignore

This file was deleted.

32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
# Nuxt.js Hacker News
# Nuxt3 Hacker News

HackerNews clone built with [Nuxt.js](https://nuxtjs.org).
Hacker News clone built with [Nuxt3](https://v3.nuxtjs.org).

<p align="center">
<a href="https://hn.nuxtjs.org" target="_blank">
<img width="1090" alt="Screenshot 2019-06-04 at 13 27 51" src="https://user-images.githubusercontent.com/904724/58875721-97382400-86cc-11e9-94c6-af21544817bb.png">
<img width="1090" src="https://user-images.githubusercontent.com/904724/58875721-97382400-86cc-11e9-94c6-af21544817bb.png">
<br>
Live Demo
</a>
</p>

## Modes
## Deploy

- Universal: https://hn.nuxtjs.org

> Hosted on [Now 2](https://zeit.co): `npm run build` + `now.json`
> Hosted on [Vercel](https://vercel.com/): `npm run build`
atinux marked this conversation as resolved.
Show resolved Hide resolved

- Single Page: https://hn-spa.nuxtjs.org

> Hosted on [Netlify](https://www.netlify.com): `npm run build-spa` + `dist/` directory
> Hosted on [Netlify](https://www.netlify.com): `npm run build-spa`

## Performance

- Lighthouse [100/100](https://cdn.rawgit.com/Atinux/e2f424e6794babc00d2158406b0ab37d/raw/4de834145881697ea83292b381df5f591f1ed2f5/lighthouse-result-nuxt.html) - [Webpagetest](https://www.webpagetest.org/lighthouse.php?test=170620_PG_a2a9feaf4ace07a61b2c6c2a171b1c79&run=1)
- Interactive (Faster 3G) [3.5s](https://www.webpagetest.org/result/170620_PG_a2a9feaf4ace07a61b2c6c2a171b1c79)
- Interactive (Emerging Markets) [3.8s](https://www.webpagetest.org/result/170620_B1_0b83d61272c77c16c3f3f1f16fb72d2e)
- Lighthouse [100/100](https://pagespeed.web.dev/report?url=https%3A%2F%2Fhackernews-git-nuxt3-nuxt-js.vercel.app%2Fnews%2F1) (Slow 4G / Mobile Moto G4)
- Interactive: 1.4s
- Total Blocking Time: 30ms

## Features

- Server Side Rendering
- Vite-based hot module replacement (HMR) dev environment
- Deploys anywhere with zero config (Vercel, Netlify, Cloudflare, etc.) powered by [Nitro](https://github.com/unjs/nitro)
- Code Splitting
- Single-file Vue Components
- Prefetch/Preload JS + DNS + Data
- Critical Path CSS
- PWA experience using [PWA Module](https://pwa.nuxtjs.org) with almost _zero config_
- PRPL
- Hot reloading dev environment integrated with [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/)
- Hosted on [Vercel](https://vercel.com)

## Build Setup

**Requires Node.js 8+**
**Requires Node.js 14+**

``` bash
# install dependencies
Expand All @@ -59,7 +55,7 @@ npm start
npm run build-spa

# serve in production mode (spa)
npm run start-spa # or upload dist/ directory
npm run start-spa # or upload .output/public/ directory

# validate code with ESLint (with Prettier)
npm run lint
Expand All @@ -70,7 +66,7 @@ npm run lintfix

## Links

For the communiy typescript fork please see [nuxt-community/hackernews-nuxt-ts](https://github.com/nuxt-community/hackernews-nuxt-ts)
For the Nuxt 2 version, check out the [`nuxt2` branch](https://github.com/nuxt/hackernews/tree/nuxt2)

## License

Expand Down
22 changes: 22 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
useHead({
titleTemplate: 'Nuxt HN | %s',
meta: [
{ property: 'og:image', content: 'https://user-images.githubusercontent.com/11247099/169022756-cdb6ef6f-1299-4ce0-8f80-81fb6e86a2e1.png' },
{ name: 'description', content: 'Hacker News clone built with Nuxt 3' },
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:site', content: '@nuxt_js' },
{ name: 'twitter:creator', content: '@nuxt_js' },
{ name: 'twitter:image', content: 'https://user-images.githubusercontent.com/11247099/169022756-cdb6ef6f-1299-4ce0-8f80-81fb6e86a2e1.png' }
],
link: [
{ rel: 'icon', type: 'image/png', href: '/icon.png' }
]
})
</script>

<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
8 changes: 0 additions & 8 deletions assets/logo.svg

This file was deleted.

19 changes: 0 additions & 19 deletions common/utils.js

This file was deleted.

45 changes: 21 additions & 24 deletions components/Comment.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
<script setup lang="ts">
import { timeAgo } from '~/composables/utils'

defineProps({
comment: {
type: Object,
required: true
}
})

const open = ref(true)

function pluralize (n: number) {
return n + (n === 1 ? ' reply' : ' replies')
}
</script>

<template>
<li v-if="comment && comment.user" class="comment">
<div class="by">
<router-link :to="'/user/' + comment.user">
<NuxtLink :to="'/user/' + comment.user">
{{ comment.user }}
</router-link>
{{ comment.time | timeAgo }} ago
</NuxtLink>
{{ timeAgo(comment.time) }} ago
</div>
<div class="text" v-html="comment.content" />
<div v-if="comment.comments && comment.comments.length" :class="{ open }" class="toggle">
Expand All @@ -17,27 +34,7 @@
</li>
</template>

<script>
export default {
name: 'Comment',
props: {
comment: {
type: Object,
required: true
}
},
data () {
return {
open: true
}
},
methods: {
pluralize: n => n + (n === 1 ? ' reply' : ' replies')
}
}
</script>

<style lang="stylus">
<style lang="postcss">
.comment-children {
.comment-children {
margin-left: 1.5em;
Expand Down
43 changes: 19 additions & 24 deletions components/Item.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
<script setup lang="ts">
import { timeAgo, isAbsolute, host } from '~/composables/utils'

defineProps<{
item: any
}>()
</script>

<template>
<li class="news-item">
<span class="score">{{ item.points }}</span>
<span class="title">
<template v-if="isAbsolute(item.url)">
<a :href="item.url" target="_blank" rel="noopener">{{ item.title }}</a>
<span class="host"> ({{ item.url | host }})</span>
<span class="host"> ({{ host(item.url) }})</span>
</template>
<template v-else>
<router-link :to="'/item/' + item.id">{{ item.title }}</router-link>
<NuxtLink :to="'/item/' + item.id">{{ item.title }}</NuxtLink>
</template>
</span>
<br>
<span class="meta">
<span v-if="item.type !== 'job'" class="by">
by
<router-link :to="'/user/' + item.user">{{ item.user }}</router-link>
<NuxtLink :to="'/user/' + item.user">{{ item.user }}</NuxtLink>
</span>
<span class="time">
{{ item.time | timeAgo }} ago
{{ timeAgo(item.time) }} ago
</span>
|
<span v-if="item.type !== 'job'" class="comments-link">
|
<router-link :to="'/item/' + item.id">{{ item.comments_count }} comments</router-link>
<NuxtLink :to="'/item/' + item.id">{{ item.comments_count }} comments</NuxtLink>
</span>
</span>
</li>
</template>

<script>
export default {
name: 'NewsItem',
props: {
item: {
type: Object,
required: true
}
},
methods: {
isAbsolute (url) {
return /^https?:\/\//.test(url)
}
}
}
</script>

<style lang="stylus">
<style lang="postcss">
.news-item {
background-color: #fff;
padding: 20px 30px 20px 80px;
Expand All @@ -68,6 +59,10 @@ export default {
font-size: 0.85em;
color: #595959;

span {
margin: 0 0.2rem;
}

a {
color: #595959;
text-decoration: underline;
Expand Down
59 changes: 26 additions & 33 deletions components/ItemListNav.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
<script setup lang="ts">
const props = defineProps<{
feed: string,
page: number,
maxPage: number
}>()

const hasMore = $computed(() => props.page < props.maxPage)
</script>

<template>
<div class="news-list-nav">
<router-link v-if="page > 1" :to="`/${feed}/${page - 1}`">
<NuxtLink v-if="page > 1" :to="`/${feed}/${page - 1}`">
&lt; prev
</router-link>
<a v-else class="disabled">&lt; prev</a>
<span>{{ page }}/{{ maxPage }}</span>
<router-link v-if="hasMore" :to="`/${feed}/${page + 1}`">
</NuxtLink>
<span v-else class="disabled">&lt; prev</span>
<span class="page">{{ page }}/{{ maxPage }}</span>
<NuxtLink v-if="hasMore" :to="`/${feed}/${page + 1}`">
more &gt;
</router-link>
<a v-else class="disabled">more &gt;</a>
</NuxtLink>
<span v-else class="disabled">more &gt;</span>
</div>
</template>

<script>
export default {
props: {
feed: {
type: String,
required: true
},
page: {
type: Number,
required: true
},
maxPage: {
type: Number,
required: true
}
},
computed: {
hasMore () {
return this.page < this.maxPage
}
}
}
</script>

<style lang="stylus">
<style lang="postcss">
.news-list-nav, .news-list {
background-color: #fff;
border-radius: 2px;
Expand All @@ -46,13 +32,20 @@ export default {
padding: 15px 30px;
text-align: center;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
user-select: none;

a {
margin: 0 1em;
}

.disabled {
opacity: 0.8;
opacity: 0.5;
}

.page {
width: 100px;
display: inline-block;
text-align: center;
}
}
</style>
Loading