Skip to content

Commit

Permalink
feat: deprecated type SocialShareNetworkData
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Dec 23, 2024
1 parent f5a49f2 commit 9cbbf35
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
import { version } from '../../package.json'
import type { NavbarLinkOptions } from '@vuepress/theme-default'
import type { SocialShareNetworkData } from 'vuepress-plugin-social-share'
import type { SocialShareNetwork } from 'vuepress-plugin-social-share'

const packageName = 'vuepress-plugin-social-share'

const extendsNetworks: SocialShareNetworkData = {
const extendsNetworks: Record<string, SocialShareNetwork> = {
pinterest: {
sharer: 'https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title',
type: 'popup',
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ For advanced usage.
```ts
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
import type { SocialShareNetworkData } from 'vuepress-plugin-social-share'
import type { SocialShareNetwork } from 'vuepress-plugin-social-share'

const extendsNetworks: SocialShareNetworkData = {
const extendsNetworks: Record<string, SocialShareNetwork> = {
pinterest: {
sharer: 'https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title',
type: 'popup',
Expand Down Expand Up @@ -217,9 +217,9 @@ i.e:
```ts
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
import type { SocialShareNetworkData } from 'vuepress-plugin-social-share'
import type { SocialShareNetwork } from 'vuepress-plugin-social-share'

const extendsNetworks: SocialShareNetworkData = {
const extendsNetworks: Record<string, SocialShareNetwork> = {
pinterest: {
sharer: 'https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title',
type: 'popup',
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/SocialShare.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { computed, defineComponent, h, onMounted, reactive, ref } from 'vue'
import { usePageFrontmatter, withBase } from 'vuepress/client'
import { isString } from '../../shared/index.js'
import { useSocialShareOptions } from '../helpers/index.js'
import { getMetaContentByName, inBrowser, isExternalUrl, isString } from '../utils.js'
import { getMetaContentByName, inBrowser, isExternalUrl } from '../utils.js'
import { SocialShareNetwork } from './SocialShareNetwork.js'
import type { PropType } from 'vue'
import type {
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/SocialShareNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useDarkmode } from '@vuepress/helper/client'
import { computed, defineComponent, h } from 'vue'
import { isString, isSVG } from '../utils.js'
import { isString } from '../../shared/index.js'
import { isSVG } from '../utils.js'
import type { PropType } from 'vue'
import type { SocialShareNetworkWithName } from '../../shared/index.js'

Expand Down
9 changes: 0 additions & 9 deletions src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ export const SVG_ICON_SHARE = `<svg viewBox="0 0 1040 1024" xmlns="http://www.w3

export const inBrowser = typeof window !== 'undefined'

/**
* Check if the given value is a string
* @param value - value to be checked
* @returns `true` if given a string
*/
export const isString = (value: unknown): value is string => {
return typeof value === 'string'
}

/**
* Check if the given source string is SVG
* @param source - given source string
Expand Down
4 changes: 2 additions & 2 deletions src/node/networks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import deepmerge from 'deepmerge'
import type { SocialShareNetworkData, SocialSharePluginOptions } from '../shared/index.js'
import type { SocialShareNetwork, SocialSharePluginOptions } from '../shared/index.js'

// @keep-sorted
export const BUILT_IN_NETWORKS = {
Expand Down Expand Up @@ -98,7 +98,7 @@ export const BUILT_IN_NETWORKS = {
},
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M389.2 48h70.6L305.6 224.2L487 464H345L233.7 318.6L106.5 464H35.8l164.9-188.5L26.8 48h145.6l100.5 132.9zm-24.8 373.8h39.1L151.1 88h-42z"/></svg>',
},
} satisfies SocialShareNetworkData
} satisfies Record<string, SocialShareNetwork>

/**
* Built-in supported network names
Expand Down
1 change: 1 addition & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './utils.js'
export * from './plugin.js'
export * from './network.js'
13 changes: 9 additions & 4 deletions src/shared/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { QRCodeToDataURLOptions } from 'qrcode'
import type { SocialShareNetwork } from './network'
import type { SocialShareNetwork, SocialShareNetworkWithName } from './network'

/**
* @deprecated use `Record<string, SocialShareNetwork>` instead
*
* @see {@link SocialShareNetwork}
*/
export type SocialShareNetworkData = Record<string, SocialShareNetwork>

/**
Expand Down Expand Up @@ -66,7 +71,7 @@ export interface SocialSharePluginOptions {
*
* @default ['twitter', 'facebook', 'reddit']
*/
networks?: string[]
networks?: (string | SocialShareNetworkWithName)[]

/**
* Twitter profile username
Expand Down Expand Up @@ -108,7 +113,7 @@ export interface SocialSharePluginOptions {
*
* @deprecated use {@link networks} instead
*/
extendsNetworks?: SocialShareNetworkData
extendsNetworks?: Record<string, SocialShareNetwork>

/**
* Set to `true` to hide SocialShare when printing
Expand All @@ -123,5 +128,5 @@ export interface SocialSharePluginOptions {
*/
export interface SocialSharePluginOptionsWithDefaults
extends Omit<SocialSharePluginOptions, 'componentName' | 'useCustomStyle'> {
networksData: SocialShareNetworkData
networksData: Record<string, SocialShareNetwork>
}
8 changes: 8 additions & 0 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Check if the given value is a string
* @param value - value to be checked
* @returns `true` if given a string
*/
export const isString = (value: unknown): value is string => {
return typeof value === 'string'
}

0 comments on commit 9cbbf35

Please sign in to comment.