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

fix: releases page #359

Merged
merged 3 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/defaultTheme/components/atoms/Alert.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="p-4 mt-4 mb-4 rounded-lg alert text-sm" :class="[type]">
<div class="p-4 mt-4 mb-4 rounded-lg alert text-sm leading-relaxed" :class="[type]">
<div class="flex items-start">
<div class="flex-grow alert-content">
<Markdown :node="$slots.default" unwrap="p" />
Expand Down
52 changes: 40 additions & 12 deletions src/defaultTheme/components/templates/Releases.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<template>
<AppContainer aside>
<AppPage>
<div class="mb-10">
<h1
class="flex items-center justify-between text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100"
>
<div class="">
<h1 class="flex-1 text-4xl font-semibold tracking-tight text-gray-900 dark:text-gray-100">
<span class="flex-1">Releases</span>
</h1>
</div>
<div class="prose max-w-none dark:prose-dark">
<div v-for="release of releases" :key="release.name">
<h2 :id="release.name" class="flex items-center justify-between">
<a :href="`#${release.name}`">
{{ release.name }}
</a>
<span class="text-base font-normal text-gray-500">{{ formatDate($i18n.local, release) }}</span>
</h2>
<NuxtContent :document="release" />
<div class="flex items-baseline justify-between">
<ProseH2 :id="release.name">
<a :href="`#${release.name}`">
{{ release.name }}
</a>
</ProseH2>
<span class="text-sm font-normal text-gray-500">{{ formatDate($i18n.local, release) }}</span>
</div>
<NuxtContent :document="release" class="docus-content" />
</div>
</div>
<hr class="mt-10 mb-4 border-gray-200 dark:border-gray-800" />
Expand All @@ -28,7 +28,8 @@
</template>

<script>
import { defineComponent, ref, useContext, useFetch } from '@nuxtjs/composition-api'
import { defineComponent, ref, useContext, useFetch, onMounted } from '@nuxtjs/composition-api'
import { scrollToHeading } from '../../utils'

export default defineComponent({
props: {
Expand All @@ -53,6 +54,33 @@ export default defineComponent({
}))
})

onMounted(() => {
if (window.location.hash) {
const hash = window.location.hash.replace('#', '')

// do not remove setTimeout (wrong scroll pos)
setTimeout(() => {
scrollToHeading(hash, '--docs-scroll-margin-block')
}, 300)
}

// do not remove setTimeout (no headers)
setTimeout(() => {
const headings = [
...document.querySelectorAll('.prose h1'),
...document.querySelectorAll('.prose h2'),
...document.querySelectorAll('.prose h3')
]
headings.forEach(heading => {
heading.addEventListener('click', e => {
e.preventDefault()
const hash = e.target.href.split('#').pop()
scrollToHeading(hash, '--docs-scroll-margin-block')
})
})
}, 500)
})

const formatDate = (locale, release) => {
const currentLocale = locale || 'en'

Expand Down
3 changes: 2 additions & 1 deletion src/defaultTheme/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function scrollToHeading(id: string, scrollMarginCssVar: string) {

// do not remove setTimeout (does not work in Safari)
setTimeout(() => {
const offset = (document.querySelector(`#${id}`) as any).offsetTop - convertPropToPixels(scrollMarginCssVar)
const escapedId = id.replace(/\./g, '\\.')
const offset = (document.querySelector(`#${escapedId}`) as any).offsetTop - convertPropToPixels(scrollMarginCssVar)
window.scrollTo(0, offset)
})
}
3 changes: 2 additions & 1 deletion src/github/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { $fetch, FetchOptions } from 'ohmyfetch/node'
import { GithubRelease, GithubReleaseOptions } from '../types/github'
import { useMarkdownParser } from '../core/parser'
import { normalizeReleaseName } from './utils'

interface GithubRawRelease {
draft: boolean
Expand Down Expand Up @@ -75,7 +76,7 @@ export async function fetchGitHubReleases({ apiUrl, repo, token }: GithubRelease
.filter((r: any) => !r.draft)
.map(release => {
return {
name: (release.name || release.tag_name).replace('Release ', ''),
name: normalizeReleaseName(release.name || release.tag_name),
date: release.published_at,
body: release.body
}
Expand Down
10 changes: 10 additions & 0 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function normalizeReleaseName(name: string) {
// remove "Release " prefix from release name
name = name.replace('Release ', '')

// make sure release name starts with an alphabetical character
if (!name.match(/^[a-zA-Z]/)) {
name = `v${name}`
}
return name
}