You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Tumblr实现基于图片文件名自动生成图片标题的功能?

在Tumblr实现自动图片标题功能的疑问

我之前在Blogger使用以下脚本实现图片标题自动插入:

<script type='text/javascript'>
//<![CDATA[

function addCaption(img) {
  var ele=$(img);
  if(ele.parent().is(".caption-wrap")) return;
  var alter = ele.attr('alt')
  var srcurl = ele.attr('src')
  var altsrc = ""  
  altsrc = srcurl + "*" + alter;
  var title=altsrc
  if(typeof title === "undefined" || title=="") return;
  if(ele.parent().is("a")) ele=ele.parent();
  var align=ele.attr("align");
  if(!align) align=ele.css("float");
  if(align=="") align="none";
  var container=ele.wrap('<div style="display:inline-block" class="caption-wrap '+align+'" />').parent();
  container.css("float", align);
  container.css("width", ele.outerWidth()+"px");
  container.css("margin-left", ele.css("margin-left"));
  container.css("margin-right", ele.css("margin-right"));
  container.css("margin-bottom", ele.css("margin-bottom"));
  ele.css("margin-left", "0px");
  ele.css("margin-right", "0px");
  ele.css("margin-bottom", "0px");
  var begin = title.lastIndexOf("/") + 1;
  var end = title.lastIndexOf(".") - 3;
  var length = end - begin + 1;
  var title = title.substr(begin, length);
  var begin = title.lastIndexOf("*") + 1;
  var title = title.substr(begin);
  var text=container.append('<p class="caption-text">Figure '+title+'</p>').find(".caption-text");
  text.css("width", ele.outerWidth()+"px");
}
// add captions on window.load to img's with class "caption"
$(window).load(function() {
  $("img").each(function() {
    addCaption(this);
  });
});
//]]>
</script>

该脚本会从图片文件名中去除扩展名及批量水印工具添加的“_w”后缀,并在名称前添加“Figure ”前缀。例如名为“1-0-1_w.jpg”的图片会自动生成标题“Figure 1-0-1”。

请问是否可以在Tumblr中实现该功能?我同时使用插入图片的文字帖和图片帖。我已查看Tumblr自定义主题文档,并在谷歌搜索相关关键词,但未找到修改Tumblr模板的相关文档或示例。


补充操作流程

我目前通过带格式的TextEdit模板离线制作帖子,标题与正文用一行等号分隔,图片标题设为斜体插入正文中。我制作了两个AppleScript,将完成的帖子拖到脚本上可分别复制标题和正文到剪贴板(等号行被忽略),之后在Tumblr编辑器中插入与标题匹配的图片。

我尝试在TextEdit中给每个标题上方添加空行,但Tumblr编辑器粘贴时会将两行空行合并为一行,暂未尝试MarkDown版本模板是否能保留空行。示例模板如下:

Title Here

=====================

*Figure 2-1-1*

Body Here

批量标签处理的AppleScript

另外,Tumblr批量编辑器无法直接粘贴标签列表(逗号分隔的标签会被识别为一个标签),因此我制作了另一个AppleScript,将保存标签的TextEdit文件拖到脚本上,可自动复制标签并输入到Tumblr批量编辑器的弹窗中,脚本代码如下:

on run
set the_file to choose file
end run

on open the_files
repeat with the_file in the_files
wipe_file(the_file)
end repeat
end open

to wipe_file(file_to_wipe)
set file_to_wipe to POSIX path of file_to_wipe

try
    
    tell application "TextEdit"
        activate
        open file_to_wipe
        
        delay 1
        
        tell application "System Events"
            key code 126 using {command down}
            key code 119 using {shift down}
            keystroke "c" using {command down}
            delay 1
            keystroke "w" using {command down}
        end tell
        
        activate application "Google Chrome"
        tell application "System Events"
            set textToType to the clipboard
            delay 1
            keystroke textToType
        end tell
        
    end tell
    
end try
end wipe_file

我近期了解到Tumblr出于安全原因移除了用户注入的JavaScript权限,但博主可个案申请使用该权限。我希望尽可能减少操作步骤以节省大量时间,目前还适配了一款用于生成按字母排序标签列表的应用。

内容的提问来源于stack exchange,提问作者user14344220

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:09:53