taproot / archive
您个人的、以indieweb和microformats为导向的HTML存档器。
v0.1.4
2022-02-22 00:27 UTC
Requires
- guzzlehttp/guzzle: ~7
- icap/html-diff: ~1
- mf2/mf2: *
- psr/http-message: ~1
Requires (Dev)
- phpunit/phpunit: ~9
README
您个人的、以indieweb和microformats为导向的HTML存档器。
用法
使用 Composer 安装: ./composer.phar require taproot/archive:~0.1
创建存档
将基本路径传递给构造函数 - 这是存档的根。
<?php $archive = new Taproot\Archive(__DIR__ . '/data/');
存档URL
用于存档URL的方法返回一个包含 [Guzzle 响应对象,Error|null] 的数组。典型用法如下
<?php list($response, $err) = $archive->archive('http://indiewebcamp.com/Taproot'); if ($err !== null) { // handle the exception, which is an instance implementing Guzzle\Common\Exception\GuzzleException } else { echo $response->getBody(true); } // The data directory now looks something like this: // data/ // http/ // indiewebcamp.com/ // Taproot/ // YYYY-MM-DDTHHMMSS.html // YYYY-MM-DDTHHMMSS-headers.txt
调用 archive
将 始终 从网络上获取页面的最新版本并返回其获取的内容。在这个过程中,它可能会根据以下条件存档
- 页面是以HTML或XHTML的形式提供的吗?如果不是,则不存档
- $force(
archive()
的第二个参数设置为true)吗?如果是,则存档 - 是否已经存在此页面的存档副本?
- 如果是,比较两个。如果它们可缓存的不同,则存档新的一个
因此,为了确保制作已缓存的HTML页面的另一个副本,无论它们是否完全相同,请调用 $archive->archive($url, true);
。
查询字符串和哈希片段在保存存档时被忽略(因此具有观点),因为哈希片段对服务器返回的HTML内容没有影响,并且使用查询字符串是糟糕的永久链接设计。
获取存档页面
有两种方法可以从存档中获取页面:获取单个副本或获取该URL存在版本ID(时间戳)的列表。
<?php $url = 'http://waterpigs.co.uk/notes/1000'; list($resp, $err) = $archive->get($url); if ($err !== null) { // Failure! There was no archived copy of that URL, and fetching it from the server returned an error response } else { // Success! Either there was an archived copy, in which case the latest one was returned, or the URL was archived as if $archive->archive($url) had been called. } $versions = $archive->archives($url); // $versions is an array of string archive IDs which match the form 'YYYY-MM-DDTHHMMSS' // getResponse allows you to get a particular archived version of a URL list($resp, $err) = $archive->getResponse($url, $versions[0]);
目前,如果您想获取URL的特定版本,您必须执行上述操作 - 在将来,get
方法将被扩展以接受日期时间,并返回最接近该时间的现有存档,默认情况下回退到新鲜副本。
测试
taproot/archive有一个最小的PHPUnit测试套件,目前仅测试一些URL到文件系统路径的情况,并对存档页面的基本功能进行了测试。
非常欢迎贡献,无论是提出问题还是发送拉取请求!如果您有一个问题并且您能够编写一个单元测试来演示它,请这样做,因为这会使其更容易修复。否则不要担心,只需提出一个尽可能详细的问题即可 :)
变更日志
v0.1.0
- 从Taproot提取的初始提取
- 测试套件的占位符
- 基本文档