Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal kernel API /api/icon/getDynamicIcon #12939

Merged
merged 6 commits into from
Oct 27, 2024

Conversation

Achuan-2
Copy link
Member

@Achuan-2 Achuan-2 commented Oct 27, 2024

思源笔记内核添加/api/icon/getDynamicIcon,使得思源笔记支持动态图标

参数

  • type:图标类型,默认为1

    • type=1:显示年月日星期
    • type=2:显示年月日
    • type=3:仅显示年月
    • type=4:仅显示年
    • type=5:当前周数
    • type=6:仅返回星期
    • type=7:倒数日
    • type=8:文字图标

    image

  • lang:中英文切换,默认为当前思源笔记使用的语言,仅在type=1、2、3、5、6、7时有效

    • lang=zh_CN:显示中文简体
    • lang=zh_CHT:显示中文繁体
    • lang=en_US/lang=en_ES:显示英文
    • 其他语言用英文显示

    image

  • color:设置配色,一共八种配色

    • color=red
    • color=blue
    • color=yellow
    • color=green
    • color=purple
    • color=pink
    • color=orange
    • color=grey

    image

    支持通过color=FE3427color=%23FE3427设置自定义颜色(注意:直接输出color=#FE3427,会由于#是URL特殊符号,导致URL被截断,会使得参数不起作用)

    image

![](api/icon/getDynamicIcon?color=FE3427&type=3)
  • date: 设置日期,默认为当前日期,日期设置格式为yyyy-mm-dd,仅在type=1-7时有效

  • weekdayType: 设置星期格式,默认为第一种类型,仅在type=1、6时有效

    • 中文

      • weekdayType=1"周日", "周一", "周二", "周三", "周四", "周五", "周六"
      • weekdayType=2"周天", "周一", "周二", "周三", "周四", "周五", "周六"
      • weekdayType=3"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
      • weekdayType=4"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六
        image
    • 英文

      • weekdayType=1"Sun","Mon","Tue","Wed","Thu","Fri","Sat"
      • weekdayType=2"SUN","MON","TUE","WED","THU","FRI","SAT"
      • weekdayType=3"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
      • weekdayType=4"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"
        image
  • content:设置文字图标的内容,默认为空,仅在type=8时有效
    注意输入下面特殊符号,需要用URL编码替代,否则导致解析参数失败或丢失

    • %: %25
    • +: %2B
    • #: %23

使用

如果是在思源笔记内部使用(不用外部软件打开),可以直接用api/icon/getDynamicIcon后添加type、color、lang、date/content等参数,例如api/icon/getDynamicIcon?color=red&type=7&lang=zh_CN
外部使用需要添加ip地址和端口,如http://127.0.0.1:6806/api/icon/getDynamicIcon

示例

type=1:显示年月日星期

默认显示今天的日期。

可通过date=2024-10-26指定显示的日期

image

![](api/icon/getDynamicIcon?color=red&lang=zh_CN&date=2024-10-27)
![](api/icon/getDynamicIcon?color=red&lang=en_US_US&date=2024-10-27)

type=2:显示年月日

image

![](api/icon/getDynamicIcon?type=2&color=red&lang=&date=2024-10-27)
![](api/icon/getDynamicIcon?type=2&color=red&lang=en_US&date=2024-10-27)

type=3:仅显示年月

image

![](api/icon/getDynamicIcon?type=3&color=red&lang=zh_CN&date=2024-10-27)
![](api/icon/getDynamicIcon?type=3&color=red&lang=en_US&date=2024-10-27)

type=4:仅显示年

image

![](api/icon/getDynamicIcon?type=4&color=red&lang=zh_CN&date=2024-10-27)

type=5:当前周数

image

![](api/icon/getDynamicIcon?type=5&color=red&lang=zh_CN&date=2024-10-27)

![](api/icon/getDynamicIcon?type=5&color=red&lang=en_US&date=2024-10-27)

type=6:仅返回星期

不输入color的话,默认星期一到星期五为红色,星期六和星期日为蓝色

image

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-21 "星期一")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-22 "星期二")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-23 "星期三")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-24 "星期四")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-25 "星期五")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-26 "星期六")

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-27 "星期日")

指定color

image

![](api/icon/getDynamicIcon?type=6&lang=en_US&date=2024-10-21&color=red "星期一")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-22&color=blue "星期二")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-23&color=green "星期三")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-24&color=yellow "星期四")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-25&color=purple "星期五")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-26&color=pink "星期六")

![](api/icon/getDynamicIcon?type=6&lang=zh_CN&date=2024-10-27&color=grey "星期日")

type=7:倒数日

该图标会显示当前日期与指定日期之间的天数。

支持 lang=en_US 修改为英文:

  • 已过Past 表示。
  • 还有Left 表示。

image

![](api/icon/getDynamicIcon?color=red&date=2024-10-22&type=7&lang=zh_CN)
![](api/icon/getDynamicIcon?color=red&date=2024-10-22&type=7&lang=en_US)

image

![](api/icon/getDynamicIcon?color=red&type=7&lang=zh_CN)
![](api/icon/getDynamicIcon?color=red&type=7&lang=en_US)

image

![](api/icon/getDynamicIcon/getDynamicIcon?color=red&date=2025-10-26&type=7&lang=zh_CN)
![](api/icon/getDynamicIcon/getDynamicIcon?color=red&date=2025-10-26&type=7&lang=en_US)

type=8:文字图标

该图标可以显示文字。

image

![](api/icon/getDynamicIcon?type=8&content=知乎&color=blue)
![](api/icon/getDynamicIcon?type=8&content=GREAT&color=red)

@88250 88250 added this to the 3.1.11 milestone Oct 27, 2024
@wish5115
Copy link

大小怎么设置?

@Achuan-2
Copy link
Member Author

Achuan-2 commented Oct 27, 2024

大小怎么设置?

返回的就是svg,如果在笔记里放,拖动设置图片大小就可以了。默认是512*512大小

kernel/api/router.go Outdated Show resolved Hide resolved
kernel/api/icon.go Outdated Show resolved Hide resolved
kernel/api/icon.go Outdated Show resolved Hide resolved
@wish5115
Copy link

大小怎么设置?

返回的就是svg,如果在笔记里放,拖动设置图片大小就可以了。默认是512*512大小

哦哦

@TCOTC
Copy link
Contributor

TCOTC commented Oct 27, 2024

我希望加一个 星期/周

参考模板这个:

image

kernel/api/icon.go Outdated Show resolved Hide resolved
kernel/api/icon.go Outdated Show resolved Hide resolved
@88250 88250 changed the title ✨ Add internal kernel API /api/icon Add internal kernel API /api/icon/getDynamicIcon Oct 27, 2024
更改locale参数为lang
新增weekdayType参数,支持设置weekday格式
@Achuan-2
Copy link
Member Author

我希望加一个 星期/周

参考模板这个:

image

已经支持
PixPin_2024-10-27_22-15-44

@88250 88250 merged commit c1a7995 into siyuan-note:dev Oct 27, 2024
@88250
Copy link
Member

88250 commented Oct 27, 2024

感谢你的贡献,思源有你更精彩!
Thank you for your contribution. SiYuan will be more wonderful with you!

88250 added a commit that referenced this pull request Oct 27, 2024
@Achuan-2
Copy link
Member Author

使用方法已经更新

@Achuan-2 Achuan-2 deleted the patch-1 branch October 28, 2024 04:22
@luo-chuan
Copy link

本机使用和伺服使用的时候,图片链接中的 ip 不一致。

有没有办法使用 siyuan://api/icon/xxxxxx 这样的链接呢?

@Wetoria
Copy link

Wetoria commented Oct 29, 2024

本机使用和伺服使用的时候,图片链接中的 ip 不一致。

有没有办法使用 siyuan://api/icon/xxxxxx 这样的链接呢?

img地址用 api/icon/xxxxxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants