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

Simple support for tiddlywiki #172

Closed
wants to merge 1 commit into from
Closed

Simple support for tiddlywiki #172

wants to merge 1 commit into from

Conversation

dneht
Copy link

@dneht dneht commented Apr 6, 2021

希望作者能添加对tiddlywiki的支持,本来我是按照NEW add zip clipping-handler来做的,但是storage-config这块没有搞得很清楚,使用默认的storage-config在saveClipping阶段backend还会调用Browser的handle而不是新增的handle

其实只是实现了两个方法putTiddler和getInfo,其他的操作都和Browser相同

function getInfo(callback) {
    Global.Fetcher.get(serverAddr + '/status', {timeout: 2, tries: 1}).then(
        (blob) => {
            callback({
                ready: true,
                supportFormats: ['md']
            });
        },
        (err) => {
            callback({
                ready: false,
                message: err.message,
                supportFormats: ['md']
            });
        }
    );
}

PS. tiddlywiki需要改造下路由,毕竟大量的图片嵌入html非常的没有必要,Browser抓取的本地图片才是最佳方案

node_modules/tiddlywiki/core/modules/server/server.js

# Server.prototype.requestHandler下添加
    var inputPath = url.parse(request.url).pathname;
    var inputSplit = inputPath.lastIndexOf(".");
    if (inputSplit > 0 && inputPath.indexOf(":") < 0) {
        var fileSuffix = inputPath.substring(inputSplit + 1)
        if (fileSuffix == "jpg" || fileSuffix == "jpeg" || fileSuffix == "png" || fileSuffix == "gif" || fileSuffix == "bmp" || fileSuffix == "webp") {
            var imageFilePath = decodeURIComponent(inputPath.substr(1));
            try {
                fs.accessSync(imageFilePath, fs.constants.R_OK);
                response.writeHead(200, {"Content-Type": "image/"+fileSuffix});
                var imageStream = fs.createReadStream(imageFilePath);
                var responseData = [];
                if (imageStream) {
                    imageStream.on("data", function(chunk) {
                      responseData.push(chunk);
                    });
                    imageStream.on("end", function() {
                       var finalData = Buffer.concat(responseData);
                       response.write(finalData);
                       response.end();
                    });
                    return;
                }
            } catch (err) {
                $tw.utils.log("Local image: [" + imageFilePath + "] read failed, will use default router...");
            }
        }
    }

@mika-cn
Copy link
Owner

mika-cn commented Apr 10, 2021

@dneht

目前不想在 MaoXian 扩展这一方增加 clipping-handler 了,因为有好多这样的需求,如果都做到这里面,确实不好维护,这点还望理解。也就是说: MaoXian 期望这些对接第三方程序的代码由个人或社区维护,而 MaoXian 这边则尽量提供「对接支持」,这样可以把更多的精力放在裁剪这个重点上。

关于对接第三方

现在有一个实验版本的 API,可以通过 userScript 或者 另一个扩展的方式,实现对裁剪结果的自行存储。这个 API 肯定还不是很完善,因为目前还没有人尝试去使用。

另:后面可能会从 「Native App」的角度,再写一些接口,以便更好地对接第三方。这个得等过些日子。

@mika-cn
Copy link
Owner

mika-cn commented Apr 10, 2021

@dneht

我看了你改的代码,如果你只是个人对接的话,使用上面我给的 API 就可以完成了,无需另新增 clipping-handler 。如果走简单路线,我推荐做成 userScript (会省去扩展更新的种种问题)。

@FSpark
Copy link

FSpark commented Apr 11, 2021

巧了,有此想法的人果然不止一个,TW要是能解决剪藏的问题就更完美了!不过正如作者所言,交由第三方实现更为合适,且TW本身的存储形式也五花八门,真要做起来还得维护个新分支...

@dneht
Copy link
Author

dneht commented Apr 16, 2021

是的,用userScript会更加简单,监听mx-wc.clipped就行了

@dneht dneht closed this Apr 16, 2021
@linonetwo
Copy link

经 TiddlyWiki Q群 群友提醒发现此贴,来交流一下,我最近打算搞这个,不过公司比较忙可能要鸽一段时间:

剪藏到 TiddlyWiki webclipper/web-clipper#845
还有
从 TiddlyWiki 发布到全平台 wechatsync/Wechatsync#33

大家看看有兴趣的也可以直接去搞看看

@linonetwo
Copy link

单文件版可以用 buggyj/tiddlyclip-plugin#122

太记还是得用 webclipper

@linonetwo
Copy link

star 这个仓库和 https://github.com/webclipper/web-clipper 很久了,但一直没空搞。今天准备搞一下试试。

https://github.com/webclipper/web-clipper 那边,作者 @DiamondYuan 虽然也是太微用户,但是好像已经很久没用了,所以也一直没支持太微,回复也不大及时,最近也没更新了,可能是阿里太忙了。

看了下这个毛线剪藏,作者还更新比较频繁,回复也很长很友好,而且基于 userscript 写插件还算比较方便,决定基于这个搞一下。

@linonetwo
Copy link

其实本来我打算用纯 userscript 来写的,以便能在火狐手机版上运行(它没法安装这个插件),但是没找到相关例子,可能userscript限制比较多吧。

想了想手机上就直接把链接收藏了,到电脑上再剪藏吧。

@FSpark
Copy link

FSpark commented May 29, 2023

以便能在火狐手机版上运行(它没法安装这个插件)

@linonetwo 之前这里 #244 (comment) 提到过,我有空去看看

@linonetwo
Copy link

目前在 https://github.com/tiddly-gittly/Maoxian-Webclipper-Tiddlywiki-Addon 尝试,但还得等我新提的几个 issue 解决了才能实际使用

@linonetwo
Copy link

linonetwo commented Oct 13, 2023

对于多文件版 (NodeJS 版、太记)请使用 https://github.com/tiddly-gittly/Browser-Extension-Tiddlywiki-Collector

抱歉,最后还是没有用上这个仓库里的扩展!因为我还想加入很多功能,比如直接在地址栏搜索,在网页上展示双链等等功能,所以必须要写个自己的插件啦,谢谢之前的支持。

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

Successfully merging this pull request may close these issues.

None yet

4 participants