SwiftDocOrg / swift-doc

A documentation generator for Swift projects
https://swiftdoc.org
MIT License
1.68k stars 99 forks source link

Provide option to incorporate directory of Markdown files into generated HTML documentation #58

Open mattt opened 4 years ago

mattt commented 4 years ago

As suggested by @MaxDesiatov in #57:

It would be great if there was an option not just to include README.md, but a given directory hierarchy of multiple markdown files that provide extended documentation: tutorials, guidelines, license, code of conduct etc.

Scoping the feature request a bit, I think a good first step would be to add a new, optional parameter to the generate command to specify a directory of Markdown files (Documentation by default) to be rendered alongside the generated symbol reference docs.

For example, given the following project structure:

.
├── Documentation
│   ├── Advanced-Usage.md
│   ├── FAQ.md
│   └── Getting-Started.md
└── Sources

swift doc generate --format html would produce three "Guide" pages for "Advanced Usage", "FAQ", and "Getting Started".

My only hesitation here is that it gets us into the business of static site generation more generally (a corollary of Zawinski's Law. To that end, I'm unsure on whether to should support any form of YAML front matter...

Edit: Actually, you know what? I'm putting my foot down: No YAML front matter! I know of a better way that doesn't add another dependency or threaten to go down a slippery slope of supporting TOML / JSON / whatever front matter — I randomly came across it in this Hugo issue thread:

@bep: This is just me thinking out loud during Christmas. I kind of like the simplicity of it. The idea is to use SGML Processing Instructions as a way to pass parameters to the new and shiny render hooks in Hugo (images and links).

So instead of this:

---
title: Getting Started
---

Reprehenderit culpa qui enim elit sunt laborum do occaecat nostrud exercitation enim ex...

You do something like this (final spelling TBD):

Reprehenderit culpa qui enim elit sunt laborum do occaecat nostrud exercitation enim ex...

<?swiftdoc title="Getting Started" ?>

Processing Instructions aren't rendered by default, and would be otherwise invisible. And unlike front matter, it can appear anywhere in the document.

If we scope this feature to Markdown files with optional PI for customization, I think that strikes a good balance for a "batteries included" output, with the option to further customize using a dedicated static site generator based on the CommonMark output.

MaxDesiatov commented 4 years ago

Another option could be to explicitly state that swift-doc focuses only on documentation generation and static site generators should handle the rest if needed, which could help in avoiding feature creep. If that's the case, it would be great to have some integration between swift-doc and say Publish and maybe an ability to reuse themes across both.

mattt commented 4 years ago

@MaxDesiatov Please see my edit, which came in after your comment.

I fully acknowledge the role for dedicated static site generators, and am committed to tailoring the CommonMark / SQLite output to support that kind of extensibility. That said, I think we can be smart about offering 80% of SSG functionality without blowing up the scope of our project.

kean commented 4 years ago

I agree with @MaxDesiatov, hosting guides alongside the API reference and using the same design language - which I really love, and which I would like to be standard for all frameworks - would be a major improvement in user experience.

I understand this probably blows up the scope significantly. But what I'm personally looking for is a comprehensive solution offering an experience similar or better to what we have at developer.apple.com. This includes guides with auto-generated links for symbols (belonging to the current module and ideally also to native frameworks) and proper semantic code highlighting which a simple static site generator can't do.

What I would also like to see is auto-generated "See Also" section:

Screen Shot 2020-04-08 at 23 51 54
kean commented 4 years ago

Hey, I hacked together a quick prototype using SwiftDoc and some of its dependencies. I hosted the end result here.

Screen Shot 2020-04-10 at 20 39 16

Some of the issues I encountered:

I also started wondering what the user experience for these kinds of guides should be. Ideally, I would probably like it to be similar to that of Xcode Playgrounds, except that instead of jump-to-definition, clicking on an element would open an API reference. If SwiftDoc could also check whether code samples in your documentation compile, great! It sounds a lot like a pipe-dream, to be honest. But maybe this is something that could be implemented using the existing tools.

Lukas-Stuehrk commented 3 years ago

I worked on a small proof of concept to continue the discussion: https://github.com/SwiftDocOrg/swift-doc/compare/master...Lukas-Stuehrk:AdditionalDocumentation

Problems solved:

Things to be discussed

The ugly parts:

Please let me know what you think. I'm happy to work on this and to bring it into a mergeable state.