@@ -86,7 +86,7 @@ const platformCategories = [
8686 },
8787 {
8888 id: ` blog ` ,
89- platforms: [` csdn ` , ` cnblogs ` , ` juejin ` , ` medium ` , ` devto ` , ` cto51 ` , ` segmentfault ` , ` oschina ` , ` infoq ` , ` jianshu ` , ` wordpress ` ],
89+ platforms: [` csdn ` , ` cnblogs ` , ` juejin ` , ` medium ` , ` devto ` , ` cto51 ` , ` segmentfault ` , ` oschina ` , ` infoq ` , ` jianshu ` , ` wordpress ` , ` substack ` ],
9090 },
9191 {
9292 id: ` cloud ` ,
@@ -106,12 +106,41 @@ function toggleCategory(categoryName: string) {
106106 }
107107}
108108
109+ const substackSetupOpen = ref (false )
110+ const substackFormHeight = ref (120 )
111+ const substackSetupUrl = computed (() => {
112+ const src = extensionInstalled .value && window .$cose ?.getSubstackSetupUrl ?.()
113+ if (! src )
114+ return null
115+ try {
116+ const url = new URL (src )
117+ if (! [' chrome-extension:' , ' moz-extension:' ].includes (url .protocol ) || url .pathname !== ' /substack-connect.html' )
118+ return null
119+ url .searchParams .set (' lang' , locale .value )
120+ return url
121+ }
122+ catch {
123+ return null
124+ }
125+ })
126+ const substackPlaceholder: PostAccount = {
127+ uid: ' substack' ,
128+ type: ' substack' ,
129+ title: ' Substack' ,
130+ displayName: ' Substack' ,
131+ icon: ' https://substack.com/favicon.ico' ,
132+ home: ' ' ,
133+ checked: false ,
134+ loggedIn: false ,
135+ }
136+
109137const accountsByCategory = computed (() => {
110138 return platformCategories .map (category => ({
111139 id: category .id ,
112140 name: t (` postInfo.categories.${category .id } ` ),
113141 accounts: category .platforms
114- .map (type => allAccounts .value .find (a => a .type === type ))
142+ .map (type => allAccounts .value .find (a => a .type === type )
143+ ?? (type === ' substack' && extensionInstalled .value ? substackPlaceholder : undefined ))
115144 .filter ((a ): a is PostAccount => a !== undefined ),
116145 }))
117146})
@@ -157,6 +186,7 @@ watch(dialogVisible, (newVal) => {
157186 }
158187 else {
159188 wordPressSetupOpen .value = false
189+ substackSetupOpen .value = false
160190 }
161191})
162192
@@ -362,6 +392,30 @@ useEventListener('message', (event: MessageEvent) => {
362392 }
363393})
364394
395+ function initializeSubstackFrame(event : Event ) {
396+ const url = substackSetupUrl .value
397+ const frame = event .currentTarget as HTMLIFrameElement
398+ if (url )
399+ frame .contentWindow ?.postMessage ({ type: ' cose-substack-initialize' }, ` ${url .protocol }//${url .host } ` )
400+ }
401+
402+ useEventListener (' message' , (event : MessageEvent ) => {
403+ const url = substackSetupUrl .value
404+ const frame = document .querySelector <HTMLIFrameElement >(' #substack-setup-frame' )
405+ if (! url || ! frame || event .source !== frame .contentWindow || event .origin !== ` ${url .protocol }//${url .host } ` )
406+ return
407+
408+ if (event .data ?.type === ' cose-substack-form-height' ) {
409+ const height = event .data .height
410+ if (Number .isInteger (height ) && height > 0 && height <= 640 )
411+ substackFormHeight .value = height
412+ }
413+ else if (event .data ?.type === ' cose-substack-connection-changed' ) {
414+ substackSetupOpen .value = false
415+ startLoginDetection ()
416+ }
417+ })
418+
365419function onAvatarError(account : PostAccount , event : Event ) {
366420 const img = event .target as HTMLImageElement
367421 if (! account )
@@ -410,7 +464,7 @@ onBeforeMount(() => {
410464 </DialogTrigger >
411465 <DialogContent
412466 class="!max-w-[95vw] !w-[min(750px,95vw)] max-h-[85vh] flex flex-col overflow-hidden"
413- @interact-outside =" wordPressSetupOpen && $event .preventDefault ()"
467+ @interact-outside =" ( wordPressSetupOpen || substackSetupOpen ) && $event .preventDefault ()"
414468 >
415469 <DialogHeader >
416470 <DialogTitle >{{ t('postInfo.title') }}</DialogTitle >
@@ -528,7 +582,7 @@ onBeforeMount(() => {
528582 <Loader2 class="ml-1 h-3.5 w-3.5 animate-spin text-muted-foreground" />
529583 <span class =" text-xs text-muted-foreground" >{{ t('postInfo.checking') }}</span >
530584 </template >
531- <template v-else-if =" isSignedInAccount (account )" >
585+ <template v-else-if =" isSignedInAccount (account ) || ( account . type === ' substack ' && account . loggedIn ) " >
532586 <img
533587 v-if =" account.avatar"
534588 :src =" account.avatar"
@@ -558,8 +612,11 @@ onBeforeMount(() => {
558612 >
559613 {{ t(devtoGuideOpen ? 'postInfo.devtoCollapse' : 'postInfo.devtoConnect') }}
560614 </button >
615+ <span v-else-if =" account.type === 'substack' && !substackSetupUrl" class =" text-xs text-muted-foreground" >
616+ {{ t('postInfo.substackUpdateExtension') }}
617+ </span >
561618 <Primitive
562- v-else-if =" account .type !== ' wordpress' "
619+ v-else-if =" account .type !== ' wordpress' && account . type !== ' substack ' "
563620 as="a"
564621 :href =" getPlatformUrl (account .type )"
565622 target="_blank"
@@ -568,6 +625,16 @@ onBeforeMount(() => {
568625 >
569626 {{ t('common.login') }}
570627 </Primitive >
628+ <button
629+ v-if =" account.type === 'substack' && !account.isChecking && substackSetupUrl"
630+ type =" button"
631+ class =" ml-1 shrink-0 text-sm text-primary hover:underline"
632+ :aria-expanded =" substackSetupOpen"
633+ aria-controls =" substack-setup"
634+ @click =" substackSetupOpen = !substackSetupOpen"
635+ >
636+ {{ substackSetupOpen ? t('common.close') : isSignedInAccount(account) ? t('commandPalette.group.settings') : t('postInfo.substackConnect') }}
637+ </button >
571638 <button
572639 v-if =" account.type === 'wordpress' && !account.isChecking && wordPressSetupUrl"
573640 type =" button"
@@ -579,6 +646,21 @@ onBeforeMount(() => {
579646 {{ wordPressSetupOpen ? t('common.close') : isSignedInAccount(account) ? t('commandPalette.group.settings') : t('common.login') }}
580647 </button >
581648 </div >
649+ <div
650+ v-if =" substackSetupOpen && substackSetupUrl && category.accounts.some(account => account.type === 'substack')"
651+ id =" substack-setup"
652+ class =" rounded-md border p-3 sm:col-span-2"
653+ >
654+ <iframe
655+ id =" substack-setup-frame"
656+ :src =" substackSetupUrl.href"
657+ title =" Substack"
658+ referrerpolicy =" no-referrer"
659+ class =" block w-full rounded-md border-0"
660+ :style =" { height: `${substackFormHeight}px` }"
661+ @load =" initializeSubstackFrame"
662+ />
663+ </div >
582664 <div
583665 v-if =" wordPressSetupOpen && wordPressSetupUrl && category.accounts.some(account => account.type === 'wordpress')"
584666 id =" wordpress-setup"
0 commit comments