Skip to content

Commit 0b9ecc2

Browse files
authored
Editing page and reporting issues (#10)
* Add github repo link to app config * Draft edit button * GitHub actions buttons layout * Create issue link * More space between content and GitHub buttons
1 parent 2382899 commit 0b9ecc2

File tree

5 files changed

+142
-12
lines changed

5 files changed

+142
-12
lines changed

app.config.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,33 @@
1717
import type { ModuleOptions } from 'nuxt-icon'
1818

1919
interface ExactproDocsOptions {
20-
title?: string
20+
/**
21+
* Title of the documentation.
22+
* It will be displayed in the header and in the browser tab.
23+
*/
24+
title: string
25+
/**
26+
* Configuration for GitHub integration
27+
*/
28+
github: {
29+
/**
30+
* Link to the repository on GitHub
31+
*/
32+
repoLink?: string
33+
/**
34+
* Name of the default branch on GitHub
35+
*
36+
* @default 'master'
37+
*/
38+
branch?: string
39+
/**
40+
* Path to the directory with documentation files on GitHub
41+
* Specify if the documentation is stored in a subdirectory of the repository.
42+
*
43+
* @default '/'
44+
*/
45+
docsDir?: string
46+
}
2147
}
2248

2349
declare module 'nuxt/schema' {
@@ -30,7 +56,12 @@ declare module 'nuxt/schema' {
3056

3157
export default defineAppConfig({
3258
exactproDocs: {
33-
title: 'Exactpro Docs'
59+
title: 'Exactpro Docs',
60+
github: {
61+
repoLink: undefined as string | undefined,
62+
branch: 'master',
63+
docsDir: '/'
64+
}
3465
},
3566
// TODO: Workaround for nuxt-icon types module, delete when https://github.com/nuxt-modules/icon/pull/63 is resolved
3667
nuxtIcon: {}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!--
2+
~ Copyright 2023 Exactpro (Exactpro Systems Limited)
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<script setup lang="ts">
18+
import type { ParsedContent } from '@nuxt/content/dist/runtime/types'
19+
20+
const props = defineProps<{
21+
doc: Pick<ParsedContent, string>
22+
}>()
23+
24+
const githubInfo = useAppConfig().exactproDocs.github
25+
26+
const { data: editBasePath } = useFetch(
27+
'/api/_docs-toolkit/github/edit-base-path'
28+
)
29+
30+
const editPath = computed(() => {
31+
return `${editBasePath.value}/${props.doc._source}/${props.doc._file}`
32+
})
33+
34+
const createIssuePath = computed(() => {
35+
return `${githubInfo.repoLink}/issues/new/choose`
36+
})
37+
</script>
38+
39+
<template>
40+
<div
41+
v-if="githubInfo.repoLink"
42+
class="flex justify-end gap-4 flex-wrap items-center"
43+
>
44+
<a :href="editPath" class="github-action-button">
45+
<Icon
46+
class="w-4 h-4 mr-2 text-primary"
47+
name="heroicons:pencil-square-solid"
48+
/>
49+
<span>Edit this page</span>
50+
</a>
51+
<a :href="createIssuePath" class="github-action-button">
52+
<Icon
53+
class="w-4 h-4 mr-2 text-error"
54+
name="heroicons:chat-bubble-left-20-solid"
55+
/>
56+
<span>Create issue</span>
57+
</a>
58+
</div>
59+
</template>
60+
61+
<style>
62+
.github-action-button {
63+
@apply bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded inline-flex items-center;
64+
}
65+
</style>

docs/app.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
export default defineAppConfig({
1818
exactproDocs: {
19-
title: 'Docs Template Project'
19+
title: 'Docs Template Project',
20+
github: {
21+
repoLink: 'https://github.com/exactpro/docs-toolkit',
22+
branch: 'master',
23+
docsDir: '/docs'
24+
}
2025
}
2126
})

pages/[...slug].vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
<Title>{{ doc ? doc.title : '' }}</Title>
2020
</Head>
2121
<NuxtLayout>
22-
<article class="px-4 mt-10 mb-96">
23-
<ContentRenderer v-if="doc && doc._type === 'markdown'" :value="doc">
24-
<ContentRendererMarkdown :value="doc" class="gevamu-prose" />
25-
</ContentRenderer>
26-
<div v-else-if="doc" class="gevamu-prose w-screen">
27-
<h1>{{ doc._dir.title }} pages</h1>
28-
<!-- TODO: Generate index page -->
29-
</div>
30-
</article>
22+
<div class="px-4 mt-10 mb-96">
23+
<article class="mb-10">
24+
<ContentRenderer v-if="doc && doc._type === 'markdown'" :value="doc">
25+
<ContentRendererMarkdown :value="doc" class="gevamu-prose" />
26+
</ContentRenderer>
27+
<div v-else-if="doc" class="gevamu-prose w-screen">
28+
<h1>{{ doc._dir.title }} pages</h1>
29+
<!-- TODO: Generate index page -->
30+
</div>
31+
</article>
32+
<EpLayoutGithubActions v-if="doc" :doc="doc" />
33+
</div>
3134
</NuxtLayout>
3235
</template>
3336

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2023 Exactpro (Exactpro Systems Limited)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import path from 'path'
18+
19+
export default defineEventHandler(() => {
20+
const config = useAppConfig()
21+
const { repoLink, branch, docsDir } = config.exactproDocs.github
22+
if (!repoLink) {
23+
throw new Error('GitHub repository link is not specified')
24+
}
25+
return path.join(repoLink, 'edit', branch, docsDir).replaceAll('\\', '/')
26+
})

0 commit comments

Comments
 (0)