11<script lang="ts" setup>
2- import type { RendererObject } from " marked" ;
3- import { marked } from " marked" ;
2+ import type { RendererObject } from ' marked'
3+ import bash from ' @shikijs/langs/bash'
4+ import githubDark from ' @shikijs/themes/github-dark'
5+ import githubLight from ' @shikijs/themes/github-light'
6+ import { marked } from ' marked'
7+ import { createHighlighterCoreSync } from ' shiki/core'
8+ import { createJavaScriptRegexEngine } from ' shiki/engine/javascript'
49
510const props = defineProps <{
6- owner: string ;
7- repo: string ;
8- }>();
11+ owner: string
12+ repo: string
13+ }>()
914
10- const data = await $fetch (" /api/repo/commits" , {
15+ const data = await $fetch (' /api/repo/commits' , {
1116 query: {
1217 owner: props .owner ,
1318 repo: props .repo ,
1419 },
15- });
20+ })
1621
1722if (! data ) {
18- throw createError (" Could not load Commits" );
23+ throw createError (' Could not load Commits' )
1924}
2025
21- const branch = shallowReactive (data );
26+ const branch = shallowReactive (data )
2227
2328const commitsWithRelease = computed (() =>
2429 branch .target .history .nodes
25- .filter (( commit ) =>
30+ .filter (commit =>
2631 commit .statusCheckRollup ?.contexts .nodes .some (
27- ( context ) => context .name === " Continuous Releases" ,
32+ context => context .name === ' Continuous Releases' ,
2833 ),
2934 )
30- .map (( commit ) => ({
35+ .map (commit => ({
3136 ... commit ,
3237 release: commit .statusCheckRollup .contexts .nodes .find (
33- ( context ) => context .name === " Continuous Releases" ,
38+ context => context .name === ' Continuous Releases' ,
3439 )! ,
3540 })),
36- );
41+ )
3742
3843const selectedCommit = shallowRef <
3944 (typeof commitsWithRelease .value )[number ] | null
40- > (null );
45+ > (null )
4146
4247// Markdown
4348
4449// Add target to links
45- const renderer: RendererObject = {
46- link(originalLink ) {
47- const link = marked .Renderer .prototype .link .call (this , originalLink );
48- return link .replace (" <a" , " <a target='_blank' rel='noreferrer' " );
49- },
50- };
51- marked .use ({ renderer });
5250
53- // Pagination
51+ const colorMode = useColorMode ()
52+ let shiki: HighlighterCore
53+
54+ onBeforeMount (() => {
55+ shiki = createHighlighterCoreSync ({
56+ themes: [githubDark , githubLight ],
57+ langs: [bash ],
58+ engine: createJavaScriptRegexEngine (),
59+ })
60+
61+ const renderer: RendererObject = {
62+ link(originalLink ) {
63+ const link = marked .Renderer .prototype .link .call (this , originalLink )
64+ return link .replace (' <a' , ' <a target=\' _blank\' rel=\' noreferrer\' class=\' text-primary underline\' ' )
65+ },
66+ code({ text }) {
67+ return ` <code class="language-bash">${shiki .codeToHtml (text , {
68+ theme: colorMode .value === ' dark' ? ' github-dark' : ' github-light' ,
69+ lang: ' bash' ,
70+ })}</code> `
71+ },
72+ }
73+
74+ marked .use ({ renderer })
75+ })
5476
55- const fetching = ref (false );
56- const fetchMoreForceDisabled = ref (! commitsWithRelease .value .length );
77+ onBeforeUnmount (() => {
78+ shiki .dispose ()
79+ })
80+
81+ // Pagination
82+ const fetching = ref (false )
83+ const fetchMoreForceDisabled = ref (! commitsWithRelease .value .length )
5784
5885async function fetchMore() {
5986 if (! branch .target .history .pageInfo .hasNextPage ) {
60- return ;
87+ return
6188 }
6289
6390 if (fetching .value ) {
64- return ;
91+ return
6592 }
6693
6794 try {
68- fetching .value = true ;
95+ fetching .value = true
6996
70- const cursor = branch .target .history .pageInfo .endCursor ;
97+ const cursor = branch .target .history .pageInfo .endCursor
7198
72- const result = await $fetch (" /api/repo/commits" , {
99+ const result = await $fetch (' /api/repo/commits' , {
73100 query: {
74101 owner: props .owner ,
75102 repo: props .repo ,
76103 cursor ,
77104 },
78- });
105+ })
79106
80- const count = commitsWithRelease .value .length ;
107+ const count = commitsWithRelease .value .length
81108
82109 branch .target = {
83110 ... branch .target ,
@@ -86,13 +113,14 @@ async function fetchMore() {
86113 nodes: [... branch .target .history .nodes , ... result .target .history .nodes ],
87114 pageInfo: result .target .history .pageInfo ,
88115 },
89- };
116+ }
90117
91118 if (count === commitsWithRelease .value .length ) {
92- fetchMoreForceDisabled .value = true ;
119+ fetchMoreForceDisabled .value = true
93120 }
94- } finally {
95- fetching .value = false ;
121+ }
122+ finally {
123+ fetching .value = false
96124 }
97125}
98126 </script >
@@ -162,15 +190,16 @@ async function fetchMore() {
162190 class =" flex flex-col items-center gap-4 border border-gray-100 dark:border-gray-800 rounded-xl p-8"
163191 >
164192 <UIcon name="i-ph-crane-tower-light" class="text-6xl opacity-50" />
165- <p class =" text-center text-lg" >No Continuous Releases found</p >
193+ <p class =" text-center text-lg" >
194+ No Continuous Releases found
195+ </p >
166196 <p class =" text-center" >
167197 Setup continuous releases with
168198 <a
169199 href =" https://github.com/stackblitz-labs/pkg.pr.new"
170200 target =" _blank"
171201 class =" text-primary"
172- >pkg.pr.new</a
173- >
202+ >pkg.pr.new</a >
174203 first!
175204 </p >
176205 </div >
@@ -218,7 +247,7 @@ async function fetchMore() {
218247 </div >
219248
220249 <div
221- class =" max-w-full p-4 border border-gray-100 dark:border-gray-800 rounded-lg prose dark:prose-invert"
250+ class =" max-w-full p-4 overflow-x-scroll border border-gray-100 dark:border-gray-800 rounded-lg prose dark:prose-invert flex flex-col gap-2 "
222251 v-html =" marked(selectedCommit.release.text)"
223252 />
224253 </div >
0 commit comments