少女
333 字
2 分钟
Hexo Fluid添加一言及出处
2023-11-26

原版只能显示hitokoto(正文)部分,不能显示from(出处)部分

  1. 修改themes\fluid\layout\_partials\plugins\typed.ejs替换为如下内容
<% if(theme.fun_features.typing.enable && in_scope(theme.fun_features.typing.scope) && page.subtitle !== false) { %>
  <%- js_ex(theme.static_prefix.typed, '/typed.min.js') %>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text;
      <% if (is_home() && theme.index.slogan.api && theme.index.slogan.api.enable) { %>
        jQuery.ajax({
          type: '<%= theme.index.slogan.api.method %>',
          url: '<%- theme.index.slogan.api.url %>',
          headers: <%- JSON.stringify(theme.index.slogan.api.headers || {}) %>,
          dataType: 'json',
          success: function(result) {
            var apiText;
            if (result) {
              var keys = '<%= theme.index.slogan.api.keys %>'.split(',');
              if (result instanceof Array) {
                result = result[0];
              }
              for (const k of keys) {
                var value = result[k];
                if (typeof value === 'string') {
                  apiText = value;
                  break;
                } else if (value instanceof Object) {
                  result = value;
                }
              }
              text = apiText ? (result.<%= theme.index.slogan.api.keys %> + ' - ' + result.<%= theme.index.slogan.api.keys2 %>) : (result.<%= theme.index.slogan.api.keys %> + ' - ' + result.<%= theme.index.slogan.api.keys2 %>);
            }
            typing(text);
          },
          error: function(xhr, status, error) {
            if (error) {
              console.error('Failed to request <%= theme.index.slogan.api.url %>:', error);
            }
            typing(text);
          }
        })
      <% } else { %>
        text = subtitle.getAttribute('data-typed-text');
        typing(text);
      <% } %>
    })(window, document);
  </script>
<% } %>
  1. 修改_config.fluid.yml
    添加keys2用于控制出处的取值
      # 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
      # The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
      keys: ['hitokoto']
      keys2: ['from']
Hexo Fluid添加一言及出处
https://onaniishoujo.github.io/posts/hexo-fluid添加一言及出处/
作者
オナニー少女
发布于
2023-11-26
许可协议
CC BY-NC-SA 4.0