Skip to content

Commit

Permalink
feat: Add apiRedirectUrl options
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Jan 15, 2022
1 parent 4848568 commit cbc76c2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ export default {
},
computed: {
name () {
name() {
return this.item.symbolName
},
type () {
type() {
return this.item.symbolType
},
link () {
return `${this.item.path.replace(/\/\//gi, '/')}.html`
link() {
return this.getApiLink(this.item)
},
deprecated () {
deprecated() {
return this.item.status.find(status => status.key === 'deprecated' || status === 'deprecated')
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<template>
<ApiSymbol v-if="item.length" :item="item[0]"/>
<span v-else-if="query">Unable to find something: <code>{{this.query}}</code></span>
<span v-else-if="query">Unable to find something: <code>{{ this.query }}</code></span>
</template>
<script>
import ApiSymbol from './ApiSymbol'
import ApiSymbol from './ApiSymbol'
export default {
name: 'ApiSymbolQuery',
components: {
ApiSymbol
},
props: {
query: {
type: String,
default: ''
}
},
computed: {
item () {
return this.$filterSymbols(this.query)
}
export default {
name: 'ApiSymbolQuery',
components: {
ApiSymbol
},
props: {
query: {
type: String,
default: ''
}
},
computed: {
item() {
return this.filterSymbols(this.query)
}
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="max-w-xl mx-auto p-8">
<div class="max-w-xl mx-auto py-5">
<div class="flow-root">
<ul class="-mb-8 reset-list">
<li v-for="item of items" :key="item.id">
Expand Down Expand Up @@ -133,4 +133,4 @@ export default {
margin: 0;
padding: 0;
}
</style>
</style>
54 changes: 9 additions & 45 deletions packages/vuepress-common/src/components/organisms/api/Api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</div>
</template>
<script>
import LazyHydrate from 'vue-lazy-hydration'
import BxIcon from '../../atoms/icons/BxIcon'
import ApiList from '../../molecules/api-list/ApiList'
import InputText from '../../molecules/input-text/InputText'
Expand All @@ -54,56 +55,19 @@ export default {
Select
},
data () {
data() {
return {
currentStatus: '',
currentType: '',
keyword: ''
keyword: '',
modules: []
}
},
computed: {
api () {
return this.$site.themeConfig.api
},
modules () {
const { modules } = this.$site.themeConfig.api
if (!modules) {
return {}
}
return Object.keys(modules)
.sort((a, b) => a < b ? -1 : 1)
.reduce((acc, key) => {
const symbols = modules[key]
.symbols
.filter((symbol) => {
if (!!(this.currentType && symbol.symbolType !== this.currentType)) {
return false
}
if (!!(this.currentStatus && symbol.status.indexOf(this.currentStatus))) {
return false
}
if (!!this.keyword) {
return symbol.symbolName.toLowerCase().indexOf(this.keyword.toLocaleLowerCase()) > -1
}
return true
})
acc[key] = { ...modules[key], symbols }
return acc
}, {})
}
mounted() {
// this.modules = this.getApiModules()
},
methods: {
onTypeChange (item) {
onTypeChange(item) {
this.currentType = item.value
if (this.$ga) {
Expand All @@ -116,7 +80,7 @@ export default {
}
},
onStatusChange (item) {
onStatusChange(item) {
this.currentStatus = item.value
if (this.$ga) {
Expand All @@ -129,7 +93,7 @@ export default {
}
},
onKeywordsChange (evt) {
onKeywordsChange(evt) {
if (this.$ga) {
this.$ga.event({
eventCategory: 'api',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<div :style="styles" class="overflow-auto">
<div :style="styles">
<Releases :items="items"/>
</div>

Expand Down Expand Up @@ -68,4 +68,4 @@ export default {
}
}
}
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export default {
components: {
BxIcon,
WarehouseStats,
LazyHydrate,
CardPlugin,
LazyHydrate,
Observer
},
directives: {
Expand Down Expand Up @@ -394,4 +394,4 @@ export default {
}
}
}
</script>
</script>
1 change: 1 addition & 0 deletions packages/vuepress-common/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './styles/index.css'

export * from './components'
export * from './mixins/ApiMixin'
export * from './utils'
export * from './clients/GithubClient'
export * from './clients/OpenCollectiveClient'
62 changes: 62 additions & 0 deletions packages/vuepress-common/src/mixins/ApiMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {filterSymbols} from '../utils'

export const ApiMixin = {
created() {

},
methods: {
getApi() {
return this.$themeConfig.api || {}
},
getApiModules() {
const modules = this.getApi()

if (!modules) {
return {}
}

return Object.keys(modules)
.sort((a, b) => a < b ? -1 : 1)
.reduce((acc, key) => {

const symbols = modules[key]
.symbols
.filter((symbol) => {
if (!!(this.currentType && symbol.symbolType !== this.currentType)) {
return false
}

if (!!(this.currentStatus && symbol.status.indexOf(this.currentStatus))) {
return false
}

if (!!this.keyword) {
return symbol.symbolName.toLowerCase().indexOf(this.keyword.toLocaleLowerCase()) > -1
}

return true
})

acc[key] = {...modules[key], symbols}

return acc
}, {})
},
getApiRedirectUrl() {
return this.$themeConfig.apiRedirectUrl || ''
},
filterSymbols(query) {
const items = filterSymbols(this.getApi())(query)

return items.map((item) => {
return {
...item,
link: this.getApiLink(item)
}
})
},
getApiLink(item) {
return `${this.getApiRedirectUrl()}${item.path.replace(/\/\//gi, '/')}.html`
}
}
}
1 change: 1 addition & 0 deletions packages/vuepress-theme-tsed/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = {
sidebar: 'auto',
docsBranch: 'production',
api: require('./public/api.json'),
apiRedirectUrl: 'https://api-doc.tsed.io',
smoothScroll: true,
lastUpdated: 'Last updated',
// algolia: {
Expand Down
13 changes: 3 additions & 10 deletions packages/vuepress-theme-tsed/src/install.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import * as common from '@tsed/vuepress-common'
import { filterSymbols } from '@tsed/vuepress-common'

function isVueComponent (component) {
function isVueComponent(component) {
return component.name && typeof component !== 'function'
}

export default function install (Vue) {
Vue.mixin({
created () {
if (this.$themeConfig.api) {
this.$filterSymbols = filterSymbols(this.$themeConfig.api)
}
}
})
export default function install(Vue) {
Vue.mixin(common.ApiMixin)

try {
Object.keys(common).forEach((key) => {
Expand Down

0 comments on commit cbc76c2

Please sign in to comment.