|
1 | 1 | <template>
|
2 | 2 | <main class="page">
|
3 |
| - <slot name="top"/> |
| 3 | + <slot name="top" /> |
4 | 4 |
|
5 |
| - <Content class="theme-default-content"/> |
| 5 | + <Content /> |
| 6 | + <PageEdit /> |
6 | 7 |
|
7 |
| - <footer class="page-edit"> |
8 |
| - <div |
9 |
| - class="edit-link" |
10 |
| - v-if="editLink" |
11 |
| - > |
12 |
| - <a |
13 |
| - :href="editLink" |
14 |
| - target="_blank" |
15 |
| - rel="noopener noreferrer" |
16 |
| - >{{ editLinkText }}</a> |
17 |
| - <OutboundLink/> |
18 |
| - </div> |
| 8 | + <PageNav v-bind="{ sidebarItems }" /> |
19 | 9 |
|
20 |
| - <div |
21 |
| - class="last-updated" |
22 |
| - v-if="lastUpdated" |
23 |
| - > |
24 |
| - <span class="prefix">{{ lastUpdatedText }}: </span> |
25 |
| - <span class="time">{{ lastUpdated }}</span> |
26 |
| - </div> |
27 |
| - </footer> |
28 |
| - |
29 |
| - <div class="page-nav" v-if="prev || next"> |
30 |
| - <p class="inner"> |
31 |
| - <span |
32 |
| - v-if="prev" |
33 |
| - class="prev" |
34 |
| - > |
35 |
| - ← |
36 |
| - <router-link |
37 |
| - v-if="prev" |
38 |
| - class="prev" |
39 |
| - :to="prev.path" |
40 |
| - > |
41 |
| - {{ prev.title || prev.path }} |
42 |
| - </router-link> |
43 |
| - </span> |
44 |
| - |
45 |
| - <span |
46 |
| - v-if="next" |
47 |
| - class="next" |
48 |
| - > |
49 |
| - <router-link |
50 |
| - v-if="next" |
51 |
| - :to="next.path" |
52 |
| - > |
53 |
| - {{ next.title || next.path }} |
54 |
| - </router-link> |
55 |
| - → |
56 |
| - </span> |
57 |
| - </p> |
58 |
| - </div> |
59 |
| - |
60 |
| - <slot name="bottom"/> |
| 10 | + <slot name="bottom" /> |
61 | 11 | </main>
|
62 | 12 | </template>
|
63 | 13 |
|
64 | 14 | <script>
|
65 |
| -import isString from 'lodash/isString' |
66 |
| -import isNil from 'lodash/isNil' |
67 |
| -
|
68 |
| -import { resolvePage, outboundRE, endingSlashRE } from '../util' |
| 15 | +import PageEdit from '@theme/components/PageEdit.vue' |
| 16 | +import PageNav from '@theme/components/PageNav.vue' |
69 | 17 |
|
70 | 18 | export default {
|
71 |
| - props: ['sidebarItems'], |
72 |
| -
|
73 |
| - computed: { |
74 |
| - lastUpdated () { |
75 |
| - return this.$page.lastUpdated |
76 |
| - }, |
77 |
| -
|
78 |
| - lastUpdatedText () { |
79 |
| - if (typeof this.$themeLocaleConfig.lastUpdated === 'string') { |
80 |
| - return this.$themeLocaleConfig.lastUpdated |
81 |
| - } |
82 |
| - if (typeof this.$site.themeConfig.lastUpdated === 'string') { |
83 |
| - return this.$site.themeConfig.lastUpdated |
84 |
| - } |
85 |
| - return 'Last Updated' |
86 |
| - }, |
87 |
| -
|
88 |
| - prev () { |
89 |
| - return resolvePageLink(LINK_TYPES.PREV, this) |
90 |
| - }, |
91 |
| -
|
92 |
| - next () { |
93 |
| - return resolvePageLink(LINK_TYPES.NEXT, this) |
94 |
| - }, |
95 |
| -
|
96 |
| - editLink () { |
97 |
| - if (this.$page.frontmatter.editLink === false) { |
98 |
| - return |
99 |
| - } |
100 |
| - const { |
101 |
| - repo, |
102 |
| - editLinks, |
103 |
| - docsDir = '', |
104 |
| - docsBranch = 'master', |
105 |
| - docsRepo = repo |
106 |
| - } = this.$site.themeConfig |
107 |
| -
|
108 |
| - if (docsRepo && editLinks && this.$page.relativePath) { |
109 |
| - return this.createEditLink(repo, docsRepo, docsDir, docsBranch, this.$page.relativePath) |
110 |
| - } |
111 |
| - }, |
112 |
| -
|
113 |
| - editLinkText () { |
114 |
| - return ( |
115 |
| - this.$themeLocaleConfig.editLinkText |
116 |
| - || this.$site.themeConfig.editLinkText |
117 |
| - || `Edit this page` |
118 |
| - ) |
119 |
| - } |
120 |
| - }, |
121 |
| -
|
122 |
| - methods: { |
123 |
| - createEditLink (repo, docsRepo, docsDir, docsBranch, path) { |
124 |
| - const bitbucket = /bitbucket.org/ |
125 |
| - if (bitbucket.test(repo)) { |
126 |
| - const base = outboundRE.test(docsRepo) |
127 |
| - ? docsRepo |
128 |
| - : repo |
129 |
| - return ( |
130 |
| - base.replace(endingSlashRE, '') |
131 |
| - + `/src` |
132 |
| - + `/${docsBranch}/` |
133 |
| - + (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '') |
134 |
| - + path |
135 |
| - + `?mode=edit&spa=0&at=${docsBranch}&fileviewer=file-view-default` |
136 |
| - ) |
137 |
| - } |
138 |
| -
|
139 |
| - const base = outboundRE.test(docsRepo) |
140 |
| - ? docsRepo |
141 |
| - : `https://github.com/${docsRepo}` |
142 |
| - return ( |
143 |
| - base.replace(endingSlashRE, '') |
144 |
| - + `/edit` |
145 |
| - + `/${docsBranch}/` |
146 |
| - + (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '') |
147 |
| - + path |
148 |
| - ) |
149 |
| - } |
150 |
| - } |
151 |
| -} |
152 |
| -
|
153 |
| -function resolvePrev (page, items) { |
154 |
| - return find(page, items, -1) |
155 |
| -} |
156 |
| -
|
157 |
| -function resolveNext (page, items) { |
158 |
| - return find(page, items, 1) |
159 |
| -} |
160 |
| -
|
161 |
| -const LINK_TYPES = { |
162 |
| - NEXT: { |
163 |
| - resolveLink: resolveNext, |
164 |
| - getThemeLinkConfig: ({ nextLinks }) => nextLinks, |
165 |
| - getPageLinkConfig: ({ frontmatter }) => frontmatter.next |
166 |
| - }, |
167 |
| - PREV: { |
168 |
| - resolveLink: resolvePrev, |
169 |
| - getThemeLinkConfig: ({ prevLinks }) => prevLinks, |
170 |
| - getPageLinkConfig: ({ frontmatter }) => frontmatter.prev |
171 |
| - } |
172 |
| -} |
173 |
| -
|
174 |
| -function resolvePageLink (linkType, { $themeConfig, $page, $route, $site, sidebarItems }) { |
175 |
| - const { resolveLink, getThemeLinkConfig, getPageLinkConfig } = linkType |
176 |
| -
|
177 |
| - // Get link config from theme |
178 |
| - const themeLinkConfig = getThemeLinkConfig($themeConfig) |
179 |
| -
|
180 |
| - // Get link config from current page |
181 |
| - const pageLinkConfig = getPageLinkConfig($page) |
182 |
| -
|
183 |
| - // Page link config will overwrite global theme link config if defined |
184 |
| - const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig |
185 |
| -
|
186 |
| - if (link === false) { |
187 |
| - return |
188 |
| - } else if (isString(link)) { |
189 |
| - return resolvePage($site.pages, link, $route.path) |
190 |
| - } else { |
191 |
| - return resolveLink($page, sidebarItems) |
192 |
| - } |
193 |
| -} |
194 |
| -
|
195 |
| -function find (page, items, offset) { |
196 |
| - const res = [] |
197 |
| - flatten(items, res) |
198 |
| - for (let i = 0; i < res.length; i++) { |
199 |
| - const cur = res[i] |
200 |
| - if (cur.type === 'page' && cur.path === decodeURIComponent(page.path)) { |
201 |
| - return res[i + offset] |
202 |
| - } |
203 |
| - } |
| 19 | + components: { PageEdit, PageNav }, |
| 20 | + props: ['sidebarItems'] |
204 | 21 | }
|
205 |
| -
|
206 |
| -function flatten (items, res) { |
207 |
| - for (let i = 0, l = items.length; i < l; i++) { |
208 |
| - if (items[i].type === 'group') { |
209 |
| - flatten(items[i].children || [], res) |
210 |
| - } else { |
211 |
| - res.push(items[i]) |
212 |
| - } |
213 |
| - } |
214 |
| -} |
215 |
| -
|
216 | 22 | </script>
|
217 | 23 |
|
218 | 24 | <style lang="stylus">
|
219 |
| -@require '../styles/wrapper.styl' |
220 |
| -
|
221 |
| -.page |
222 |
| - padding-bottom 2rem |
223 |
| - display block |
224 |
| -
|
225 |
| -.page-edit |
226 |
| - @extend $wrapper |
227 |
| - padding-top 1rem |
228 |
| - padding-bottom 1rem |
229 |
| - overflow auto |
230 |
| - .edit-link |
231 |
| - display inline-block |
232 |
| - a |
233 |
| - color lighten($textColor, 25%) |
234 |
| - margin-right 0.25rem |
235 |
| - .last-updated |
236 |
| - float right |
237 |
| - font-size 0.9em |
238 |
| - .prefix |
239 |
| - font-weight 500 |
240 |
| - color lighten($textColor, 25%) |
241 |
| - .time |
242 |
| - font-weight 400 |
243 |
| - color #aaa |
244 |
| -
|
245 |
| -.page-nav |
246 |
| - @extend $wrapper |
247 |
| - padding-top 1rem |
248 |
| - padding-bottom 0 |
249 |
| - .inner |
250 |
| - min-height 2rem |
251 |
| - margin-top 0 |
252 |
| - border-top 1px solid $borderColor |
253 |
| - padding-top 1rem |
254 |
| - overflow auto // clear float |
255 |
| - .next |
256 |
| - float right |
257 |
| -
|
258 |
| -@media (max-width: $MQMobile) |
259 |
| - .page-edit |
260 |
| - .edit-link |
261 |
| - margin-bottom .5rem |
262 |
| - .last-updated |
263 |
| - font-size .8em |
264 |
| - float none |
265 |
| - text-align left |
266 |
| -
|
| 25 | +.page { |
| 26 | + padding-bottom: 2rem; |
| 27 | + display: block; |
| 28 | +} |
267 | 29 | </style>
|
0 commit comments