Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samvtran committed Jan 11, 2022
0 parents commit a221ab8
Show file tree
Hide file tree
Showing 13 changed files with 152,096 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
optimizedIndex.dsidx
searchKitIndex.dsidx
aTbRef.docset/Contents/Resources/Documents
docSet.dsidx
437 changes: 437 additions & 0 deletions CONTENT-LICENSE

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions DocsetGenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
25 changes: 25 additions & 0 deletions DocsetGenerator/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "GRDB",
"repositoryURL": "https://github.com/groue/GRDB.swift.git",
"state": {
"branch": null,
"revision": "dfca044433050bb3e297761bf827e01ef376f5d9",
"version": "5.18.0"
}
},
{
"package": "Kanna",
"repositoryURL": "git@github.com:tid-kijyun/Kanna.git",
"state": {
"branch": null,
"revision": "f9e4922223dd0d3dfbf02ca70812cf5531fc0593",
"version": "5.2.7"
}
}
]
},
"version": 1
}
28 changes: 28 additions & 0 deletions DocsetGenerator/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "DocsetGenerator",
platforms: [
.macOS(.v11)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.executable(
name: "DocsetGenerator",
targets: ["DocsetGenerator"]),
],
dependencies: [
.package(url: "git@github.com:tid-kijyun/Kanna.git", from: "5.2.7"),
.package(url: "https://github.com/groue/GRDB.swift.git", from: "5.18.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.executableTarget(
name: "DocsetGenerator",
dependencies: ["Kanna", .product(name: "GRDB", package: "GRDB.swift")])
]
)
3 changes: 3 additions & 0 deletions DocsetGenerator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DocsetGenerator

A description of this package.
117 changes: 117 additions & 0 deletions DocsetGenerator/Sources/DocsetGenerator/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Foundation
import GRDB
import Kanna

let env = ProcessInfo.processInfo.environment

guard let htmlPath = env["TBX_REF_PATH"],
let docsetPath = env["TBX_DOCSET_PATH"] else {
print("TBX_REF_PATH and TBX_DOCSET_PATH must be set to paths on your filesystem")
exit(1)
}

let docsetUrl = URL(fileURLWithPath: docsetPath)
let resourcesUrl = docsetUrl.appendingPathComponent("Contents/Resources")
let databaseUrl = resourcesUrl.appendingPathComponent("docSet.dsidx")
let htmlUrl = resourcesUrl.appendingPathComponent("Documents")

let fileManager = FileManager()
let dbQueue = try DatabaseQueue(path: databaseUrl.path)

enum ItemType: String, Codable {
case Attribute
case Guide
case Operator
case Resource
case Section
case Trait
case `Type`
}

/// https://kapeli.com/docsets#createsqlite
struct SearchIndex: Codable, FetchableRecord, PersistableRecord {
let id: Int64?
let name: String
let type: ItemType
let path: String
}

let knownDirectoryItemTypes: [String: ItemType] = [
htmlUrl.appendingPathComponent("index/Attributes/SystemAttributeList").path: .Attribute,
htmlUrl.appendingPathComponent("index/ActionsRules/Operators/FullOperatorList").path: .Operator
]

func pageType(for pageUrl: URL) -> ItemType {
let parent = pageUrl.deletingLastPathComponent()

if let directoryType = knownDirectoryItemTypes[parent.path] {
return directoryType
}

return .Guide
}

func parseFile(atPath path: String) throws -> SearchIndex {
let pageUrl = URL(fileURLWithPath: path, relativeTo: htmlUrl)
let doc = try HTML(url: pageUrl, encoding: .utf8)

let name = doc.title ?? "Chapter"

return SearchIndex(
id: nil,
name: name,
type: pageType(for: pageUrl),
path: path
)
}

func copyFiles() throws {
let htmlSourceUrl = URL(fileURLWithPath: htmlPath)

try? fileManager.removeItem(at: htmlUrl)
try fileManager.copyItem(at: htmlSourceUrl, to: htmlUrl)

let iconSourceUrl = htmlSourceUrl.appendingPathComponent("images/tinderbox9sm.png")
let iconUrl = docsetUrl.appendingPathComponent("icon.png")

try? fileManager.removeItem(at: iconUrl)
try fileManager.copyItem(at: iconSourceUrl, to: iconUrl)
}

func parseHtmlFiles() throws -> [SearchIndex] {
let enumerator = fileManager.enumerator(atPath: htmlUrl.path)!

var htmlFiles = [SearchIndex]()
while let file = enumerator.nextObject() as? String {
guard file.hasSuffix(".html"),
let indexablePage = try? parseFile(atPath: file)
else {
continue
}
htmlFiles.append(indexablePage)
}

return htmlFiles
}

try copyFiles()
let files = try parseHtmlFiles()

try dbQueue.write { db in
if try db.tableExists("searchindex") {
try db.drop(table: "searchindex")
}
try db.create(table: "searchindex") { t in
t.autoIncrementedPrimaryKey("id")
t.column("name", .text)
t.column("type", .text)
t.column("path", .text)
t.uniqueKey(["name", "type", "path"], onConflict: .replace)
}

for file in files {
try file.insert(db)
}
}

print("Indexed \(files.count) files in the Tinderbox docset")
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 Sam Tran

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# A Tinderbox Reference File Dash Docset

This repository contains a [Dash](https://kapeli.com/dash) docset for [aTbRef](https://acrobatfaq.com/atbref9/), an invaluable resource for [Tinderbox](https://www.eastgate.com/Tinderbox/) users.

## Quickstart
- Download aTbRef.docset.zip from the latest release in the Releases tab
- Unzip the docset, put it somewhere safe, and open it in Dash
- Enjoy!

## What Works
- Dark mode
- Internal links (if any don't resolve correctly, please open an issue 🙏)
- _Open Online Page_ links to the online version at https://acrobatfaq.com/atbref9/

## TODO
- [ ] Ensure all links can resolve interally
- [ ] Host a docset feed
- [ ] Verify page types (most are guide)

## Modifications
The following modifications have been made to `aTbRef-9.tbx` file included in this repo:
- `here` quicklink has been removed since it's not particularly useful inside Dash
- Google Analytics, Google search, and DuckDuckGo search have been disabled.

## Generating Your Own Docset
Follow the directions at [Obtaining the aTbRef source TBX file](https://acrobatfaq.com/atbref9/index/AboutaTbRef/ObtainingtheaTbRefsource.html) to prepare a full HTML export of the aTbRef file.

After generating an export, open the DocsetGenerator project in Xcode. Edit the Run scheme of the project to include two environment variables:
- `TBX_REF_PATH` - The absolute path to aTbRef HTML export; e.g., `/Users/me/Documents/aTbRef Export`
- `TBX_DOCSET_PATH` - The absolute path to this repository's aTbRef.docset folder; e.g., `/Users/me/Documents/aTbRef-Docset/aTbRef.docset`

Run DocsetGenerator to generate the necessary files.

Finally, open the `aTbRef.docset` package with Dash to install the local docset.

## Licenses
DocsetGenerator is covered by the MIT license included in the `LICENSE` file.

All textual content is licensed as below:

A Tinderbox Reference File (c) by Mark Anderson

A Tinderbox Reference File is licensed under a
Creative Commons Attribution 4.0 International License.

You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by/4.0/>.
Loading

0 comments on commit a221ab8

Please sign in to comment.