halo-dev / halo

强大易用的开源建站工具。
https://www.halo.run
GNU General Public License v3.0
34.19k stars 9.73k forks source link

feat: 支持获取主题 settings.yaml 配置文件中的节点列表 #530

Closed ruibaby closed 2 years ago

ruibaby commented 4 years ago

概述

获取 settings.yaml 文件中一个节点的列表,集合类型。使用自定义标签获取。

动机

减少代码量。

详细解释

某些设置选项的格式是固定的,比如社交资料。如下:

subnav:
  label: 社交设置
  items:
    github:
      name: github
      label: Github
      type: text
    weibo:
      name: weibo
      label: 微博
      type: text
    zhihu:
      name: zhihu
      label: 知乎
      type: text
    qq:
      name: qq
      label: QQ
      type: text
    weixin:
      name: weixin
      label: 微信
      type: text
    jianshu:
      name: jianshu
      label: 简书
      type: text
    douban:
      name: douban
      label: 豆瓣
      type: text
    segmentfault:
      name: segmentfault
      label: SegmentFault
      type: text
    bilibili:
      name: bilibili
      label: bilibili
      type: text
    acfun:
      name: acfun
      label: AcFun
      type: text
    mail:
      name: mail
      label: Mail
      type: text
    facebook:
      name: facebook
      label: Facebook
      type: text
    google:
      name: google
      label: Google
      type: text
    twitter:
      name: twitter
      label: Twitter
      type: text
    linkedin:
      name: linkedin
      label: Linkedin
      type: text

目前我们在页面上要获取数据只能一个一个的获取,如:

<div class="social">
          <#if settings.github?? && settings.github!=''>
            <a class="github" target="_blank" href="${settings.github!}" title="github"><i class="icon-github"></i></a>
          </#if>
          <#if settings.weibo?? && settings.weibo!=''>
            <a class="weibo" target="_blank" href="${settings.weibo!}" title="weibo"><i class="icon-weibo"></i></a>
          </#if>
          <#if settings.zhihu?? && settings.zhihu!=''>
            <a class="zhihu" target="_blank" href="${settings.zhihu!}" title="zhihu"><i class="icon-zhihu"></i></a>
          </#if>
          <#if settings.qq?? && settings.qq!=''>
            <a class="qq" target="_blank" href="${settings.qq!}" title="qq"><i class="icon-qq"></i></a>
          </#if>
          <#if settings.weixin?? && settings.weixin!=''>
            <a class="weixin" target="_blank" href="${settings.weixin!}" title="weixin"><i class="icon-weixin"></i></a>
          </#if>
          <#if settings.jianshu?? && settings.jianshu!=''>
            <a class="jianshu" target="_blank" href="${settings.jianshu!}" title="jianshu"><i class="icon-jianshu"></i></a>
          </#if>
          <#if settings.douban?? && settings.douban!=''>
            <a class="douban" target="_blank" href="${settings.douban!}" title="douban"><i class="icon-douban"></i></a>
          </#if>
          <#if settings.segmentfault?? && settings.segmentfault!=''>
            <a class="segmentfault" target="_blank" href="${settings.segmentfault!}" title="segmentfault"><i class="icon-segmentfault"></i></a>
          </#if>
          <#if settings.bilibili?? && settings.bilibili!=''>
            <a class="bilibili" target="_blank" href="${settings.bilibili!}" title="bilibili"><i class="icon-bilibili"></i></a>
          </#if>
          <#if settings.acfun?? && settings.acfun!=''>
            <a class="acfun" target="_blank" href="${settings.acfun!}" title="acfun"><i class="icon-acfun"></i></a>
          </#if>
          <#if settings.mail?? && settings.mail!=''>
            <a class="mail" target="_blank" href="${settings.mail!}" title="mail"><i class="icon-mail"></i></a>
          </#if>
          <#if settings.facebook?? && settings.facebook!=''>
            <a class="facebook" target="_blank" href="${settings.facebook!}" title="facebook"><i class="icon-facebook"></i></a>
          </#if>
          <#if settings.google?? && settings.google!=''>
            <a class="google" target="_blank" href="${settings.google!}" title="google"><i class="icon-google"></i></a>
          </#if>
          <#if settings.twitter?? && settings.twitter!=''>
            <a class="twitter" target="_blank" href="${settings.twitter!}" title="twitter"><i class="icon-twitter"></i></a>
          </#if>
          <#if settings.linkedin?? && settings.linkedin!=''>
            <a class="linkedin" target="_blank" href="${settings.linkedin!}" title="linkedin"><i class="icon-linkedin"></i></a>
          </#if>
</div>

这种做法相当不科学,希望能做到这样:

<@themeTag method="listItem" item="subnav">
    <#list items as item>
        <a class="${item.name!}" target="_blank" href="${item.value!}" title="${item.label!}"><i class="icon-${item.name!}"></i></a>
    </#list>
</@themeTag>
JohnNiang commented 4 years ago

这里可能需要新增一个 metadata 来设置各种属性。

ruibaby commented 2 years ago

这个 issue 已经不适用于目前的场景。

/close

f2c-ci-robot[bot] commented 2 years ago

@ruibaby: Closing this issue.

In response to [this](https://github.com/halo-dev/halo/issues/530#issuecomment-1312670187): >这个 issue 已经不适用于目前的场景。 > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.