[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 24 02:09:17 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: None (PeterChou1)
<details>
<summary>Changes</summary>
issue: https://github.com/llvm/llvm-project/issues/92867
I solved the problem by making the js use absolute path instead relative I think this also makes it more permanent since there is no need to compute relative path anymore
---
Full diff: https://github.com/llvm/llvm-project/pull/93281.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-doc/assets/index.js (+35-37)
``````````diff
diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
- if (!New)
- return Base;
- if (Base)
- Base += "/";
- Base += New;
- return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
- var Path = FilePath;
- while (Path) {
- if (CurrentDirectory == Path)
- return FilePath.substring(Path.length + 1);
- Path = Path.substring(0, Path.lastIndexOf("/"));
- }
-
- var Dir = CurrentDirectory;
- var Result = "";
- while (Dir) {
- if (Dir == FilePath)
- break;
- Dir = Dir.substring(0, Dir.lastIndexOf("/"));
- Result = append(Result, "..")
+function genLink(Ref) {
+ var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+ if (Ref.RefType !== "namespace") {
+ if (Ref.Path === "") {
+ Path = `${Path}${Ref.Name}.html`;
+ }
+ else {
+ Path = `${Path}/${Ref.Name}.html`;
+ }
}
- Result = append(Result, FilePath.substring(Dir.length))
- return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
- var Path = computeRelativePath(Ref.Path, CurrentDirectory);
- if (Ref.RefType == "namespace")
- Path = append(Path, "index.html");
- else
- Path = append(Path, Ref.Name + ".html")
- ANode = document.createElement("a");
+ ANode = document.createElement("a");
ANode.setAttribute("href", Path);
var TextNode = document.createTextNode(Ref.Name);
ANode.appendChild(TextNode);
return ANode;
}
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+ // Out will store the HTML elements that Index requires to be generated
+ var Out = [];
+ if (Index.Name) {
+ var SpanNode = document.createElement("span");
+ var TextNode = document.createTextNode(Index.Name);
+ SpanNode.appendChild(genLink(Index));
+ Out.push(SpanNode);
+ }
+ if (Index.Children.length == 0)
+ return Out;
+ // Only the outermost list should use ol, the others should use ul
+ var ListNodeName = IsOutermostList ? "ol" : "ul";
+ var ListNode = document.createElement(ListNodeName);
+ for (Child of Index.Children) {
+ var LiNode = document.createElement("li");
+ ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+ for (Node of ChildNodes)
+ LiNode.appendChild(Node);
+ ListNode.appendChild(LiNode);
+ }
+ Out.push(ListNode);
+ return Out;
+}
+
function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
// Out will store the HTML elements that Index requires to be generated
var Out = [];
``````````
</details>
https://github.com/llvm/llvm-project/pull/93281
More information about the cfe-commits
mailing list