godbout / dash-docset-builder
PHP 中的 Dash (LOVE) Docset Builder。
3.0.1
2022-05-28 07:02 UTC
Requires
- php: ^8.0.2
- illuminate/database: ^9.0
- laravel-zero/framework: ^9.0
- league/flysystem: ^3
- nunomaduro/collision: ^6.0
- symfony/css-selector: ^6.0
- symfony/dom-crawler: ^6.0
- vlucas/phpdotenv: ^5.0
- wa72/htmlpagedom: ^3.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32
- hassankhan/config: ^3.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5.20
- scrutinizer/ocular: ^1.9
This package is auto-updated.
Last update: 2024-09-07 16:54:14 UTC
README
这个家伙会为你创建 Dash Docset。当然,你仍然需要在你的类中声明一些东西。这个家伙还不能读懂你的心思。更多信息见下文。
DASH IS LOVE
当使用 Sublime + Chrome 在分屏视图中编码时,Dash 是救星 ❤️
如何使用(也称为用法)
安装这个酷炫的工具(含糊其辞的意思)
composer require godbout/dash-docset-builder
生成你漂亮的 Docset 类
dash-docset new my-pretty-docset
你现在有一个漂亮的 MyPrettyDocset
类,你需要对其进行编辑。见下文。
编辑你的漂亮 Docset 类
你的 Docset 类必须扩展 BaseDocset 类,该类实现了 Docset 接口。这允许 Builder 仅通过少量配置即可制作你的 Docset。
你的 Docset 类必须定义以下常量
// To generate the docset filename public const CODE = 'tailwindcss'; // What name will show up in Dash public const NAME = 'Tailwind CSS'; // Where to download the doc from public const URL = 'tailwindcss.com'; // What page should the docset show by default public const INDEX = 'installation.html'; // A link to try the service/app, if any public const PLAYGROUND = 'https://codesandbox.io/s/github/lbogdan/tailwindcss-playground'; // Where to grab the icon in 16x16 res public const ICON_16 = 'favicon-16x16.png'; // Where to grab the icon in 32x32 res public const ICON_32 = 'favicon-32x32.png'; // List of external domains where images or other files have to // be downloaded, if not from URL defined above public const EXTERNAL_DOMAINS = [ 'refactoring-ui.nyc3.cdn.digitaloceanspaces.com', 'jsdelivr.net', 'code.jquery.com', 'rsms.me', 'googleapis.com', ];
然后有两个必须定义的方法
/** * This method is responsible for generating the Dash Table of Contents * * For each HTML file of your downloaded doc, this method will be called. * You have to parse the file (how you want) and return a collection of * entries. See Docsets in * https://github.com/godbout/dash-docsets/tree/master/app/Docsets * for examples. */ public function entries(string $file): Collection { $crawler = HtmlPageCrawler::create(Storage::get($file)); $entries = collect(); $entries = $this->generateEntries($crawler, $file); return $entries; } /** * This method is responsible for formatting the doc for Dash * * For each HTML file of your downloaded doc, this method will be called. * You have to update the content of the file and return that content. * The file is passed as argument rather than its content because sometimes * the file name is the only way you have to generate the Dash Online Redirection. * See Docsets in * https://github.com/godbout/dash-docsets/tree/master/app/Docsets * for examples. */ public function format(string $file): string { $crawler = HtmlPageCrawler::create(Storage::get($file)); $this->modifyHtml($crawler, $file); return $crawler->saveHTML(); }
Builder 提供了一种通用的方式来下载你的 Docset 文档。如果找到 sitemap.xml
,则会使用它,否则会遍历你的 Docset 索引。如果你需要提供自己的文档下载方式,你可以在你的 Docset 中定义一个 grab()
方法。Builder 会捕获它并使用你的自定义方法。
public function grab(): bool { system( "wget doc.tiki.org/All-the-Documentation \ --mirror \ -e robots=off \ --header 'Cookie: javascript_enabled_detect=true' \ --reject-regex='/Plugins-|Plugins\.html|fullscreen=|PDF\.js|tikiversion=|comzone=|structure=|wp_files_sort_mode[0-9]=|offset=|\?refresh|\?session_filters|\?sort_mode' \ --accept-regex='/Plugin|/LIST|Tiki_org_family|\.css|\.js|\.jpg|\.png|\.gif|\.svg|\.ico|\.webmanifest' \ --page-requisites \ --adjust-extension \ --convert-links \ --span-hosts \ --domains={$this->externalDomains()} \ --directory-prefix=storage/{$this->downloadedDirectory()}", $result ); return $result === 0; }
构建你的 Docset
一旦你的类设置好了,运行
dash-docset build my-pretty-docset
这将下载文档,将其打包成 .docset 文件,并在存储文件夹中创建一个存档——如果你想将其贡献给 Dash,这很有用。
享受吧
享受你的新 Docset,也许还可以与愿意分享的社区分享——这很棒,kiss kiss: https://github.com/Kapeli/Dash-User-Contributions。
使用此构建器生成的 Docset
老年人先来