Skip to content

Commit

Permalink
feat: support render platform icon
Browse files Browse the repository at this point in the history
  • Loading branch information
baozouai committed May 13, 2023
1 parent 63c69f5 commit e9e8346
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions assets/juejin.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/segmentfault.ico
Binary file not shown.
Binary file added assets/yuque.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/zhihu.ico
Binary file not shown.
14 changes: 10 additions & 4 deletions src/index.ts
Expand Up @@ -3,8 +3,7 @@ import * as core from '@actions/core'
import type { SupportPlatform } from './type'
import getPostList from './util/get_list'
import { getTimeDiffString } from './util/time'

const ASSETS_PATH = 'https://raw.githubusercontent.com/baozouai/multi-platform-posts-action/main/assets'
import { getAssetUrl } from './util/asset'

const SUPPORT_PLAT_FORM = [
/** 掘金 */
Expand All @@ -17,6 +16,12 @@ const SUPPORT_PLAT_FORM = [
'yuque',
]

const iconUrl = {
juejin: 'juejin.svg',
yuque: 'yuque.png',
zhihu: 'zhihu.ico',
segmentfault: 'segmentfault.ico',
}
async function main(): Promise<void> {
// 读取参数: 用户 ID
const USER_ID = core.getInput('user_id')
Expand All @@ -35,11 +40,12 @@ async function main(): Promise<void> {
const reduceText = commonPosts.reduce<string>((total, item) => {
const { title, publish_time, link, star, collect } = item
const time = getTimeDiffString(publish_time)
return `${total}\n<li>[${time} <img src="${ASSETS_PATH}/star.svg" width='14px'/>:${star} ${collect === null ? '' : `<img src="${ASSETS_PATH}/collect.svg" width='20px'/>:${collect}`}]
return `${total}\n<li>[${time} <img src="${getAssetUrl('star.svg')}" width='14px'/>:${star} ${collect === null ? '' : `<img src="${getAssetUrl('collect.svg')}" width='20px'/>:${collect}`}]
<a href="${link}" target="_blank">${title}</a>
</li>`
}, '')
const appendHtml = `\n<ul>${reduceText}\n</ul>\n`
const platformSvgUrl = getAssetUrl(iconUrl[PLAT_FORM])
const appendHtml = `<div align="center"><img src='${platformSvgUrl}' alt='${PLAT_FORM}'/></div>\n<ul>${reduceText}\n</ul>\n`

core.info(`3. 读取 README, 在 <!-- multi-platform-posts start --> 和 <!-- multi-platform-posts end --> 中间插入生成的 html: \n ${appendHtml}`)

Expand Down
5 changes: 5 additions & 0 deletions src/util/asset.ts
@@ -0,0 +1,5 @@
const ASSETS_PATH = 'https://raw.githubusercontent.com/baozouai/multi-platform-posts-action/main/assets/'

export function getAssetUrl(asset: string) {
return ASSETS_PATH + asset
}

0 comments on commit e9e8346

Please sign in to comment.