|
17 | 17 | <script> |
18 | 18 | const baseURL = "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/"; |
19 | 19 |
|
20 | | -const headingRedirects = { |
21 | | - "#ID461": "guidedtour#Simple-Values", |
22 | | - "#ID462": "guidedtour#Control-Flow", |
23 | | - "#ID463": "guidedtour#Functions-and-Closures", |
24 | | -} |
25 | | - |
26 | | -const chapterRedirects = { |
27 | | - "GuidedTour/GuidedTour.html": "guidedtour", |
28 | | - "GuidedTour/AboutSwift.html": "aboutswift", |
29 | | - "GuidedTour/Compatibility.html": "compatibility", |
30 | | - "GuidedTour/GuidedTour.html": "guidedtour", |
31 | | - "GuidedTour/GuidedTourPart.html": "guidedtour", |
32 | | - |
33 | | - "LanguageGuide/AccessControl.html": "accesscontrol", |
34 | | - "LanguageGuide/AdvancedOperators.html": "advancedoperators", |
35 | | - "LanguageGuide/AutomaticReferenceCounting.html": "automaticreferencecounting", |
36 | | - "LanguageGuide/BasicOperators.html": "basicoperators", |
37 | | - "LanguageGuide/ClassesAndStructures.html": "classesandstructures", |
38 | | - "LanguageGuide/Closures.html": "closures", |
39 | | - "LanguageGuide/CollectionTypes.html": "collectiontypes", |
40 | | - "LanguageGuide/Concurrency.html": "concurrency", |
41 | | - "LanguageGuide/ControlFlow.html": "controlflow", |
42 | | - "LanguageGuide/Deinitialization.html": "deinitialization", |
43 | | - "LanguageGuide/Enumerations.html": "enumerations", |
44 | | - "LanguageGuide/ErrorHandling.html": "errorhandling", |
45 | | - "LanguageGuide/Extensions.html": "extensions", |
46 | | - "LanguageGuide/Functions.html": "functions", |
47 | | - "LanguageGuide/Generics.html": "generics", |
48 | | - "LanguageGuide/Inheritance.html": "inheritance", |
49 | | - "LanguageGuide/Initialization.html": "initialization", |
50 | | - "LanguageGuide/LanguageGuidePart.html": "languageguide", |
51 | | - "LanguageGuide/MemorySafety.html": "memorysafety", |
52 | | - "LanguageGuide/Methods.html": "methods", |
53 | | - "LanguageGuide/NestedTypes.html": "nestedtypes", |
54 | | - "LanguageGuide/OpaqueTypes.html": "opaquetypes", |
55 | | - "LanguageGuide/OptionalChaining.html": "optionalchaining", |
56 | | - "LanguageGuide/Properties.html": "properties", |
57 | | - "LanguageGuide/Protocols.html": "protocols", |
58 | | - "LanguageGuide/StringsAndCharacters.html": "stringsandcharacters", |
59 | | - "LanguageGuide/Subscripts.html": "subscripts", |
60 | | - "LanguageGuide/TheBasics.html": "thebasics", |
61 | | - "LanguageGuide/TypeCasting.html": "typecasting", |
62 | | - |
63 | | - "ReferenceManual/AboutTheLanguageReference.html": "aboutthelanguagereference", |
64 | | - "ReferenceManual/Attributes.html": "attributes", |
65 | | - "ReferenceManual/Declarations.html": "declarations", |
66 | | - "ReferenceManual/Expressions.html": "expressions", |
67 | | - "ReferenceManual/GenericParametersAndArguments.html": "genericparametersandarguments", |
68 | | - "ReferenceManual/LexicalStructure.html": "lexicalstructure", |
69 | | - "ReferenceManual/Patterns.html": "patterns", |
70 | | - "ReferenceManual/ReferenceManualPart.html": "referencemanual", |
71 | | - "ReferenceManual/Statements.html": "statements", |
72 | | - "ReferenceManual/Types.html": "types", |
73 | | - "ReferenceManual/zzSummaryOfTheGrammar.html": "summaryofthegrammar", |
74 | | - |
75 | | - "RevisionHistory/RevisionHistory.html": "revisionhistory", |
76 | | - "RevisionHistory/RevisionHistoryPart.html": "revisionhistory", |
77 | | -} |
78 | | - |
79 | | -const path = window.location.pathname; |
80 | | -const hash = window.location.hash; |
81 | | - |
82 | 20 | var newURL = baseURL; |
83 | | -if (hash == "") { |
84 | | - const components = path.split("/"); |
85 | | - const part = components[components.length - 2]; |
86 | | - const chapter = components[components.length - 1]; |
87 | | - const redirectPath = chapterRedirects[part + "/" + chapter]; |
88 | | - newURL += redirectPath; |
89 | | -} else { |
90 | | - const redirectPath = headingRedirects[hash]; |
91 | | - newURL += redirectPath; |
92 | | -} |
93 | 21 |
|
94 | 22 | document.getElementById("redirect").setAttribute("href", newURL); |
95 | 23 | window.location = newURL; |
|
0 commit comments