Skip to content

Commit d077da2

Browse files
authored
Merge pull request #49 from codewars/extract-edit-on-github
2 parents 319c219 + 4baa8e7 commit d077da2

File tree

6 files changed

+70
-34
lines changed

6 files changed

+70
-34
lines changed

.github/workflows/lint.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Lint
2-
on: [pull_request]
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
37

48
jobs:
59
lint:
@@ -23,9 +27,11 @@ jobs:
2327
restore-keys: |
2428
${{ runner.os }}-yarn-
2529
- run: yarn install --frozen-lockfile
26-
- run: yarn format
30+
- if: ${{ github.event_name == 'pull_request' }}
31+
run: yarn format
2732
- run: yarn lint:text
2833
- run: yarn lint:format
29-
- uses: stefanzweifel/git-auto-commit-action@v4
34+
- if: ${{ github.event_name == 'pull_request' }}
35+
uses: stefanzweifel/git-auto-commit-action@v4
3036
with:
3137
commit_message: Autoformat with Prettier

src/components/EditOnGitHub.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<div class="mt-8 pt-8">
3+
<a
4+
:href="githubFileURL"
5+
target="_blank"
6+
class="flex flex-row items-center justify-center hover:underline"
7+
>
8+
<GithubIcon size="1x" />
9+
<span class="ml-1">Edit on GitHub</span>
10+
</a>
11+
</div>
12+
</template>
13+
14+
<static-query>
15+
query {
16+
metadata {
17+
settings {
18+
repository
19+
}
20+
}
21+
}
22+
</static-query>
23+
24+
<script>
25+
import { GithubIcon } from "vue-feather-icons";
26+
27+
export default {
28+
components: {
29+
GithubIcon,
30+
},
31+
props: {
32+
filePath: {
33+
type: String,
34+
required: true,
35+
},
36+
},
37+
computed: {
38+
githubFileURL() {
39+
const repo = this.$static.metadata.settings.repository;
40+
return `${repo}/blob/master/${this.filePath}`;
41+
},
42+
},
43+
};
44+
</script>

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This is the main.js file. Import global CSS and scripts here.
22
// The Client API can be used here. Learn more: gridsome.org/docs/client-api
33
import "@/assets/styles.css";
4-
import DefaultLayout from "@/layouts/Default.vue";
4+
import DefaultLayout from "@/layouts/Default";
55

66
export default function (Vue, { router, head, isClient }) {
77
// Set default layout as a global component

src/pages/Glossary.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
</div>
5656
</section>
5757
</div>
58+
59+
<EditOnGitHub filePath="data/glossary.yml" />
5860
</Layout>
5961
</template>
6062

@@ -90,9 +92,12 @@ query {
9092
<script>
9193
import { ExternalLinkIcon } from "vue-feather-icons";
9294
95+
import EditOnGitHub from "@/components/EditOnGitHub";
96+
9397
export default {
9498
components: {
9599
ExternalLinkIcon,
100+
EditOnGitHub,
96101
},
97102
computed: {
98103
pages() {

src/templates/Language.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
<div class="mt-8 pt-8 lg:mt-12 lg:pt-12 border-t border-ui-border">
8989
<NextPrevLinks :prev="{ title: 'Languages', path: '/languages/' }" />
9090
</div>
91+
92+
<EditOnGitHub :filePath="`data/languages/${language.id}.yml`" />
9193
</Layout>
9294
</template>
9395

@@ -121,10 +123,12 @@ query($id: ID!) {
121123

122124
<script>
123125
import NextPrevLinks from "@/components/NextPrevLinks";
126+
import EditOnGitHub from "@/components/EditOnGitHub";
124127
125128
export default {
126129
components: {
127130
NextPrevLinks,
131+
EditOnGitHub,
128132
},
129133
computed: {
130134
language() {

src/templates/MarkdownPage.vue

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@
1515
<NextPrevLinks :prev="prev" :next="next" />
1616
</div>
1717

18-
<div class="mt-8 pt-8">
19-
<a
20-
:href="githubFileURL"
21-
target="_blank"
22-
class="flex flex-row items-center justify-center hover:underline"
23-
>
24-
<GithubIcon size="1x" />
25-
<span class="ml-1">Edit on GitHub</span>
26-
</a>
27-
</div>
18+
<EditOnGitHub :filePath="filePath" />
2819
</div>
2920
</div>
3021
</Layout>
@@ -69,32 +60,26 @@ query($id: ID!) {
6960
}
7061
}
7162
}
72-
73-
metadata {
74-
settings {
75-
repository
76-
}
77-
}
7863
}
7964
</page-query>
8065

8166
<script>
82-
import { GithubIcon } from "vue-feather-icons";
83-
84-
import OnThisPage from "@/components/OnThisPage.vue";
85-
import NextPrevLinks from "@/components/NextPrevLinks.vue";
67+
import OnThisPage from "@/components/OnThisPage";
68+
import NextPrevLinks from "@/components/NextPrevLinks";
69+
import EditOnGitHub from "@/components/EditOnGitHub";
8670
8771
export default {
8872
components: {
89-
GithubIcon,
9073
OnThisPage,
9174
NextPrevLinks,
75+
EditOnGitHub,
9276
},
9377
9478
computed: {
9579
page() {
9680
return this.$page.markdownPage;
9781
},
82+
9883
headings() {
9984
return this.page.headings.filter((h) => h.depth > 1);
10085
},
@@ -115,16 +100,8 @@ export default {
115100
return this.page.prev ? this.findLinkedPage(this.page.prev) : null;
116101
},
117102
118-
repository() {
119-
return this.$page.metadata.settings.repository;
120-
},
121-
122103
filePath() {
123-
return this.page.fileInfo.path;
124-
},
125-
126-
githubFileURL() {
127-
return `${this.repository}/blob/master/content/${this.filePath}`;
104+
return `content/${this.page.fileInfo.path}`;
128105
},
129106
},
130107

0 commit comments

Comments
 (0)