Skip to content

Commit

Permalink
Redirect to repo on click code icon (#11)
Browse files Browse the repository at this point in the history
* Redirect to repo on click code icon

* Add pages support
  • Loading branch information
kadiryazici authored Oct 13, 2022
1 parent 2d466bb commit d3c25b0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pages

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
name: Pages
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build for pages
run: npm run build:pages
- name: Deploy
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: playground/dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ const activeExampleId = ref(examples[0].id);
const activeExample = computed(() =>
examples.find((example) => example.id === activeExampleId.value),
);
function handleClickSourceCode(link: string) {
window.open(link, '_blank');
}
</script>

<template>
<TheSidebar
v-model:activeExample="activeExampleId"
:examples="examples"
@clickSourceCode="({}.constructor.constructor('return console.log')()(activeExample?.code))"
@clickSourceCode="handleClickSourceCode"
/>

<div class="site-container">
Expand Down
4 changes: 2 additions & 2 deletions playground/components/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props {
interface Emits {
(e: 'update:activeExample', id: string): void;
(e: 'clickSourceCode'): void;
(e: 'clickSourceCode', link: string): void;
}
const props = withDefaults(defineProps<Props>(), { examples: () => [] });
Expand All @@ -28,7 +28,7 @@ function handleItemClick(example: Example) {
:text="example.title"
:active="props.activeExample === example.id"
@click="() => handleItemClick(example)"
@clickSourceCode="$emit('clickSourceCode')"
@clickSourceCode="$emit('clickSourceCode', example.repoLink)"
/>
</ul>
</template>
Expand Down
4 changes: 2 additions & 2 deletions playground/examples/keyboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Example } from '../../types';
import { nanoid } from 'nanoid';
import { defineAsyncComponent } from 'vue';
import code from './index.vue?raw';

const keyboardExample: Example = {
id: nanoid(),
title: 'Keyboard Support',
component: defineAsyncComponent(() => import('./index.vue')),
code,
repoLink:
'https://github.com/kadiryazici/vue-selectable-items/tree/main/playground/examples/keyboard',
};

export default keyboardExample;
4 changes: 2 additions & 2 deletions playground/examples/nested/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Example } from '../../types';
import { nanoid } from 'nanoid';
import { defineAsyncComponent } from 'vue';
import code from './index.vue?raw';

const nestedExample: Example = {
id: nanoid(),
title: 'Nested Items',
component: defineAsyncComponent(() => import('./index.vue')),
code,
repoLink:
'https://github.com/kadiryazici/vue-selectable-items/tree/main/playground/examples/nested',
};

export default nestedExample;
2 changes: 1 addition & 1 deletion playground/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Component } from 'vue';
export interface Example {
title: string;
id: string;
code?: string;
repoLink: string;
component: Component;
}

Expand Down
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ const prodConfig: UserConfigExport = {
};

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => (mode === 'production' ? prodConfig : devConfig));
export default defineConfig(({ mode }) => {
if (mode === 'production') return prodConfig;
if (mode === 'development') return devConfig;
if (mode === 'staging') return { ...devConfig, base: '/vue-selectable-items' };

throw new Error('Invalid mode');
});

0 comments on commit d3c25b0

Please sign in to comment.