Skip to content

增加公共代码 js/css 片段 #6143

@Zuoqiu-Yingyi

Description

@Zuoqiu-Yingyi
Contributor

在什么情况下你需要该特性?In what scenarios do you need this feature?

关联: [提议] 增加公共主题 css 文件, 无论使用哪个主题, 该 css 都会生效 - 链滴

描述可能的最优解决方案 Describe the optimal solution

将公共主题 theme.css 文件与 theme.js 文件塞到某个 data 目录下某个现有的静态 Web 文件服务的目录

描述候选的解决方案 Describe the candidate solution

在 data 目录下设置一个新的提供静态 Web 文件服务的目录, 用于存放公共主题的 theme.css 文件与 theme.js 文件

其他信息 Other information

不急~

Activity

Vanessa219

Vanessa219 commented on Oct 10, 2022

@Vanessa219
Member

公共主题为 stage/build/app/base.css,所有主题都会进行加载。公共 js 里面主要的是前端 API 之类的么?

removed their assignment
on Oct 10, 2022
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Oct 10, 2022

@Zuoqiu-Yingyi
ContributorAuthor

公共主题为 stage/build/app/base.css,所有主题都会进行加载。公共 js 里面主要的是前端 API 之类的么?

是指不与特定主题耦合的自定义主题片段, 优先级比用户所当前所使用的主题(theme.csscustom.css)与默认主题更高, 且无论用户切换到哪个主题都可以应用

Vanessa219

Vanessa219 commented on Oct 10, 2022

@Vanessa219
Member

哦哦哦,想起来了,抱歉抱歉。

self-assigned this
on Oct 10, 2022
added this to the 2.4.0 milestone on Oct 10, 2022
mozhux

mozhux commented on Oct 11, 2022

@mozhux

这是不是类似ob的代码片段?
如果是可以不区分启用的话,那最好是能有选择性的开启某些样式或js,在设置里调节需要的功能

88250

88250 commented on Oct 11, 2022

@88250
Member

@mozhux 这个就不区分功能了,所有功能都塞到一个 js/css 中,区分功能的话还是通过插件机制比较好。

mozhux

mozhux commented on Oct 11, 2022

@mozhux
88250

88250 commented on Oct 11, 2022

@88250
Member

我不太清楚如何区分一个文件中的不同片段 😂

9 remaining items

added a commit that references this issue on Oct 12, 2022
crendy

crendy commented on Oct 18, 2022

@crendy

问一下 公共代码 js/css 片段 怎么操作?

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Oct 18, 2022

@Zuoqiu-Yingyi
ContributorAuthor

问一下 公共代码 js/css 片段 怎么操作?

  1. 新建文件 <workspace>/data/snippets/conf.json
  2. 直接编辑该文件
terwer

terwer commented on Oct 24, 2022

@terwer
Contributor

参照D大的示例,css直接改type即可,提供给有需要的参考:

[
  {
    "name": "common",
    "type": "js",
    "enabled": true,
    "content": "console.log('这是自定义js片段');"
  },
   {
    "name": "common",
    "type": "css",
    "enabled": true,
    "content": ".protyle-background:has(.protyle-background__icon.fn__none) {min-height: 57px !important;}.protyle-title{margin-left:16px !important;margin-right:16px !important;}.protyle-wysiwyg{padding-left:16px !important;padding-right:16px !important;}"
  }
]
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Oct 24, 2022

@Zuoqiu-Yingyi
ContributorAuthor

引用第三方文件的方案:

[
    {
        "name": "-js-test-1",
        "type": "js",
        "enabled": false,
        "content": "document.currentScript.type='module';document.currentScript.src='/widgets/custom.js';"
    },
    {
        "name": "-js-test-2",
        "type": "js",
        "enabled": false,
        "content": "import('/widgets/custom.js');"
    },
    {
        "name": "-css-test-1",
        "type": "css",
        "enabled": false,
        "content": "@import url('/widgets/custom.css');"
    }
]
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Oct 26, 2022

@Zuoqiu-Yingyi
ContributorAuthor

@88250 能不能将 data/snippets 目录也建立静态 Web 文件服务, 这样就可以在 conf.json 中通过 @import url('/snippets/foo.css');import('/snippets/bar.js'); 引用了, 不然想要同步的话只能另辟蹊径放在 data/widgetsdata/emojis 目录了

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @88250@Vanessa219@terwer@crendy@leolee9086

      Issue actions

        增加公共代码 js/css 片段 · Issue #6143 · siyuan-note/siyuan