Skip to content

Commit

Permalink
refactor: move networks utils to node
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Mar 12, 2024
1 parent ffe952e commit c936090
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/shared/networks.ts → src/node/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SocialShareNetworkData } from './types.js'
import deepmerge from 'deepmerge'
import type { SocialShareNetworkData, SocialSharePluginOptions } from '../shared/index.js'

export const BASE_NETWORKS: SocialShareNetworkData = {
export const BUILT_IN_NETWORKS: SocialShareNetworkData = {
facebook: {
sharer:
'https://www.facebook.com/sharer/sharer.php?u=@url&title=@title&description=@description&quote=@quote&hashtag=@hashtags',
Expand Down Expand Up @@ -81,3 +82,12 @@ export const BASE_NETWORKS: SocialShareNetworkData = {
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1117 1024"><path d="M53.865 558.08l289.92 121.6 560-492.16-491.52 530.56 371.84 140.8c8.96 3.2 19.2-1.28 22.4-10.24V848l260.48-816.64-1014.4 494.72c-8.96 4.48-12.16 14.72-8.32 23.68 2.56 3.84 5.76 7.04 9.6 8.32zm357.76 434.56l144.64-155.52-144.64-58.88v214.4z"/></svg>',
},
}

/**
* Merge extendsNetworks with built-in networks
*
* @param options plugin options
* @returns merged networks data
*/
export const mergeNetworksData = (options: SocialSharePluginOptions) =>
deepmerge(BUILT_IN_NETWORKS, options.extendsNetworks || {})
4 changes: 2 additions & 2 deletions src/node/socialSharePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL, fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import { createNetworksData } from '../shared/index.js'
import { mergeNetworksData } from './networks.js'
import type { Plugin } from '@vuepress/core'
import type { SocialSharePluginOptions } from '../shared/index.js'

Expand All @@ -23,7 +23,7 @@ export const socialSharePlugin = (options: SocialSharePluginOptions = {}): Plugi
},

onPrepared(app) {
const networksData = createNetworksData(restOptions)
const networksData = mergeNetworksData(restOptions)
const socialShareOptions = { ...restOptions, networksData }
const content = `export const socialShareOptions = ${JSON.stringify(socialShareOptions)}`
app.writeTemp('social-share/options.js', content)
Expand Down
2 changes: 0 additions & 2 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './types.js'
export * from './utils.js'
export * from './networks.js'
6 changes: 0 additions & 6 deletions src/shared/utils.ts

This file was deleted.

0 comments on commit c936090

Please sign in to comment.