Skip to content

Commit 910c402

Browse files
authored
Add more information about where to find the Redirected values (#811)
1 parent 53aa1ae commit 910c402

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

Sources/SwiftDocC/Semantics/Redirect.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@ import Foundation
1212
import Markdown
1313

1414

15-
/// A directive that specifies an additional URL for the page where the directive appears.
15+
/// A directive that specifies a previous URL for the page where the directive appears.
1616
///
17-
/// Use this directive to declare a URL where a piece of content was previously located.
18-
/// For example, if you host the compiled documentation on a web server,
19-
/// that server can read this data and set an HTTP "301 Moved Permanently" redirect from
20-
/// the declared URL to the page's current URL and avoid breaking any existing links to the content.
17+
/// If the page has moved more than once you can add multiple `Redirected` directives, each specifying one previous URL. For example:
2118
///
22-
/// > Note: Starting with version 5.11, @Redirected is supported as a child directive of @Metadata. In
23-
/// previous versions, @Redirected must be used as a top level directive.
19+
/// ```md
20+
/// @Redirected(from: "old/path/to/this/page")
21+
/// @Redirected(from: "another/old/path/to/this/page")
22+
/// ```
2423
///
24+
/// > Note: Starting with version 5.11, the `Redirected` directive is supported both top-level and as a member of a ``Metadata`` directive. In
25+
/// earlier versions, the `Redirected` directive is only supported as a top-level directive.
26+
///
27+
/// ### Setting up Redirects
28+
///
29+
/// If you host your documentation on a web server, you can set a HTTP "301 Moved Permanently" redirect for each `Redirected` value to avoid breaking existing links to your content.
30+
///
31+
/// To find each page’s Redirected values, pass the `--emit-digest` flag to DocC.
32+
/// This flag configures DocC to write additional metadata files to the output directory.
33+
/// One of these files, `linkable-entities.json`, contains summarized information about all pages and on-page landmarks that you can link to from outside the DocC documentation.
34+
/// Each of these "entities" has a `"path"`---which represents the current relative path of that page---and an optional list of `"redirects"`---which represent all the `Redirected` values for page as they were authored in the markup.
35+
/// You can write either relative redirect values or absolute redirect values in the markup depending on what information you need when setting up HTTP "301 Moved Permanently" redirects on your web server.
2536
public final class Redirect: Semantic, AutomaticDirectiveConvertible {
2637
public static let introducedVersion = "5.5"
2738
public static let directiveName = "Redirected"

Sources/docc/DocCDocumentation.docc/DocC.symbols.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,35 +4088,44 @@
40884088
"docComment" : {
40894089
"lines" : [
40904090
{
4091-
"text" : "A directive that specifies an additional URL for the page where the directive appears."
4091+
"text" : "A directive that specifies a previous URL for the page where the directive appears."
40924092
},
40934093
{
40944094
"text" : ""
40954095
},
40964096
{
4097-
"text" : "Use this directive to declare a URL where a piece of content was previously located."
4097+
"text" : "If the page has moved more than once you can add multiple `Redirected` directives, each specifying one previous URL."
40984098
},
40994099
{
4100-
"text" : "For example, if you host the compiled documentation on a web server,"
4100+
"text" : ""
41014101
},
41024102
{
4103-
"text" : "that server can read this data and set an HTTP \"301 Moved Permanently\" redirect from"
4103+
"text" : "> Note: Starting with version 5.11, the `Redirected` directive is supported both top-level and as a member of a ``Metadata`` directive. In"
41044104
},
41054105
{
4106-
"text" : "the declared URL to the page's current URL and avoid breaking any existing links to the content."
4106+
"text" : "earlier versions, the `Redirected` directive is only supported as a top-level directive."
41074107
},
41084108
{
41094109
"text" : ""
41104110
},
41114111
{
4112-
"text" : "> Note: Starting with version 5.11, @Redirected is supported as a child directive of @Metadata. In"
4112+
"text" : "### Setting up Redirects"
4113+
},
4114+
{
4115+
"text" : ""
41134116
},
41144117
{
4115-
"text" : "previous versions, @Redirected must be used as a top level directive."
4118+
"text" : "If you host your documentation on a web server, you can set a HTTP \"301 Moved Permanently\" redirect for each `Redirected` value to avoid breaking existing links to your content."
41164119
},
41174120
{
41184121
"text" : ""
41194122
},
4123+
{
4124+
"text" : "To find each page's `Redirected` values, pass the `--emit-digest` flag to DocC and read the \"linkable-entities.json\" file that this makes DocC write to the output directory. "
4125+
},
4126+
{
4127+
"text" : "Each \"entity\" in that file has a \"path\"---which represents the current relative path of that page---and an optional list of \"redirects\"---which represent all the `Redirected` values for page as they were authored in the markup. You can write either relative redirect values or absolute redirect values depending on what information you need to set HTTP \"301 Moved Permanently\" redirects on your web server."
4128+
},
41204129
{
41214130
"text" : "- Parameters:"
41224131
},

0 commit comments

Comments
 (0)