Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit64a56f4

Browse files
refactor: Update ArgoHub documentation and redirect mapping functiona… (#1168)
* refactor: Update ArgoHub documentation and redirect mapping functionality* Test redirect functionality* Update scripts for dynamic site configuration* add logs for test* Adjust currentPath replacement logic in ArgoHub redirect* handle root path and improve URL construction* Fix redirect logic to ensure cookie check is properly enforced
1 parent7c6120d commit64a56f4

File tree

6 files changed

+97
-40
lines changed

6 files changed

+97
-40
lines changed

‎README.md‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Node version `9.11.2`
3232
2. In the ArgoHub collection, create a folder structure for the required document.
3333
3. Create a symbolic link to the document inside the required folder in the ArgoHub collection (refer to the "Create a Symlink" section for details).
3434
4. Create a record for the side menu`argohub-nav.yml` that represents the new document.
35+
>**Warning:** After adding a new side menu, it is required to delete the`_site` folder to apply the change.
3536
5. Adjust the document and add conditions for Enterprise and ArgoHub contexts if needed.
36-
6. Adjust the the document links (refter to the "Document Links" section)
37-
7. In the`argohub-redirect-mapping.js`, add a redirect link between the Enterprise and ArgoHub collections.
37+
6. Adjust the the document links (refter to the "Document Links" section).
3838

3939
##Document Changes
4040

@@ -48,15 +48,14 @@ No actions required - the new content will be automatically reflected in both Ar
4848

4949
- Repeat step 3.
5050
- Repeat step 6.
51-
- Repeat step 7.
5251

5352
####If changes to the ArgoHub structure are required
5453

55-
- Repeat steps 2 to7.
54+
- Repeat steps 2 to6.
5655

5756
###Splitting a Document into Multiple Documents
5857

59-
- Repeat steps 2 to7.
58+
- Repeat steps 2 to6.
6059

6160
##ArgoHub Collection Notes
6261

@@ -68,14 +67,20 @@ No actions required - the new content will be automatically reflected in both Ar
6867
2. Open the terminal and navigate to the directory where you want to create the symlink.
6968
3. Run the following command:`npm run link <relative-path-from-step-1>`
7069

70+
Note: In addition to creating a symlink, the command will also add a record in`argohub-redirect-mapping.json` to ensure auto-redirection functionality.
71+
7172
####Conditions to Render Text for Specific Contexts
7273

7374
- By default, all document content appears the same in both Enterprise and ArgoHub contexts.
74-
- To include content for the ArgoHub collection only:`{% if page.layout =="argohub" %}`
75-
- To exclude content from the ArgoHub collection (will appear only in the Enterprise collection):`{% if page.layout !="argohub" %}`
75+
- To include content for the ArgoHub collection only:`{% if page.collection ==site.gitops_collection %}`
76+
- To exclude content from the ArgoHub collection (will appear only in the Enterprise collection):`{% if page.collection !=site.gitops_collection %}`
7677

7778
####Document Links
7879

80+
We can rely on the automatic redirect from the Enterprise to the ArgoHub Collection (details provided in the section below) to maintain the collection context. For instance, if a link in an ArgoHub Collection document directs to the Enterprise collection, the auto-redirect will return the user to the ArgoHub Collection.
81+
82+
Additionally, we can use the following methods to avoid redirects if needed:
83+
7984
Document links will automatically adjust to the relevant context, eliminating the need for duplication. For example:
8085
`({{site.baseurl}}/{{page.collection}}/installation/gitops/shared-configuration/)`
8186

@@ -96,3 +101,5 @@ The ArgoHub home page and all pages within the ArgoHub collection are excluded f
96101
###Auto Redirect from Enterprise to ArgoHub Collection
97102

98103
When the GitOps client adds an ArgoHub system type cookie, the Documentation site will detect it and initiate an automatic redirect. If you open any page from the enterprise collection, the site will check for an equivalent document in the ArgoHub collection and redirect you there if one exists.
104+
105+
Redirect links between the Enterprise and ArgoHub collections are stored in the`argohub-redirect-mapping.json` file. Running`npm run link` automatically updates the file, eliminating the need for manual updates.

‎_config.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ link_api: "https://g.codefresh.io/api/"
141141
link_plugins:"https://codefresh.io/argohub/"
142142
link_community:"https://community.codefresh.io/"
143143

144+
gitops_collection:"argohub"
145+
144146
ga_tracking_code:"UA-53554200-2"
145147

146148
cdn:

‎_includes/scripts.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<scripttype="module"src="{{ site.baseurl }}/assets/js/src/argohub-redirect.js"></script>
1+
<script>
2+
constSITE_BASE_URL="{{ site.baseurl }}";
3+
constSITE_GITOPS_COLLECTION="{{ site.gitops_collection }}";
4+
</script>
5+
<scriptsrc="{{ site.baseurl }}/assets/js/src/argohub-redirect.js"></script>
26

37
<scriptsrc="{{ site.cdn.jquery }}"integrity="{{ site.cdn.jquery_hash }}"crossorigin="anonymous"></script>
48
<script>window.jQuery||document.write('<script src="{{ site.baseurl }}/assets/js/vendor/jquery.min.js"><\/script>')</script>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
exportconstredirectMap={
1+
{
22
"/":"/argohub/",
33
"/docs/installation/gitops/shared-configuration/":"/argohub/installation/gitops/shared-configuration/",
4-
"/docs/getting-started/intro-to-codefresh/":"/argohub/introduction/intro-to-codefresh/",
5-
};
4+
"/docs/getting-started/intro-to-codefresh/":"/argohub/introduction/intro-to-codefresh/"
5+
}

‎assets/js/src/argohub-redirect.js‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import{redirectMap}from"./argohub-redirect-mapping.js";
2-
31
constARGOHUB_DOC_COOKIE_NAME="argohubdoc";
4-
constARGOHUB_MAIN_PATH="/argohub/";
2+
constARGOHUB_MAIN_PATH=`/${SITE_GITOPS_COLLECTION}/`;
53

64
functiongetCookie(name){
75
constvalue=`;${document.cookie}`;
@@ -10,38 +8,44 @@ function getCookie(name) {
108
returnnull;
119
}
1210

13-
functiongetArgoHubRedirectURL(currentPath){
14-
if(currentPath.includes("/docs/docs/")){
15-
currentPath=currentPath.replace("/docs/docs/","/docs/");
16-
}
11+
asyncfunctiongetArgoHubRedirectURL(currentPath){
12+
currentPath=currentPath.replace(SITE_BASE_URL,"");
13+
14+
constredirectMap=awaitfetchRedirectMap();
1715

1816
constnewPath=redirectMap[currentPath];
1917
if(!newPath)returnnull;
2018

21-
letnewURL=location.href;
22-
23-
if(currentPath==="/"){
24-
constlastMatchRegex=newRegExp(`${currentPath}(?=[^${currentPath}]*$)`);
25-
newURL=newURL.replace(lastMatchRegex,newPath);
26-
}else{
27-
newURL=newURL.replace(currentPath,newPath);
28-
}
19+
constnewURL=
20+
newPath===ARGOHUB_MAIN_PATH
21+
?`${location.href}${SITE_GITOPS_COLLECTION}`
22+
:location.href.replace(currentPath,newPath);
2923

3024
returnnewURL;
3125
}
3226

33-
functionhandleRedirect(){
27+
asyncfunctionhandleRedirect(){
3428
constcurrentPath=location.pathname;
3529

3630
if(currentPath.includes(ARGOHUB_MAIN_PATH))return;
3731

3832
constredirectCookie=getCookie(ARGOHUB_DOC_COOKIE_NAME);
3933
if(!redirectCookie)return;
4034

41-
constargoHubRedirectURL=getArgoHubRedirectURL(currentPath);
35+
constargoHubRedirectURL=awaitgetArgoHubRedirectURL(currentPath);
4236
if(!argoHubRedirectURL)return;
4337

4438
window.location.href=argoHubRedirectURL;
4539
}
4640

41+
asyncfunctionfetchRedirectMap(){
42+
constresponse=awaitfetch(
43+
`${SITE_BASE_URL}/assets/js/src/argohub-redirect-mapping.json`
44+
);
45+
if(!response.ok){
46+
thrownewError("Failed to fetch the collections redirect map.");
47+
}
48+
returnresponse.json();
49+
}
50+
4751
handleRedirect();

‎build/create_symlink.js‎

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
const{ symlinkSync, existsSync}=require("node:fs");
2-
const{ basename, join, relative, resolve}=require("node:path");
1+
const{
2+
symlinkSync,
3+
existsSync,
4+
readFileSync,
5+
writeFileSync,
6+
}=require("node:fs");
7+
const{ basename, join, relative}=require("node:path");
38

49
if(process.argv.length!==3){
510
console.error("Usage: node create_symlink.js <target_file>");
@@ -18,16 +23,51 @@ const currentFolder = process.env.INIT_CWD;
1823
constdocsRoot=join(__dirname,"../");
1924
constlinkName=basename(targetFile);
2025

21-
constpath=join(currentFolder,linkName);
22-
constrelativePath=relative(docsRoot,path);
26+
constlinkPath=join(currentFolder,linkName);
27+
constrelativeLinkPath=relative(docsRoot,linkPath);
2328

24-
try{
25-
symlinkSync(resolve(targetFile),relativePath);
26-
}catch(err){
27-
console.error(`Error creating symlink:${err.message}`);
28-
process.exit(1);
29+
constrelativeTargetPath=relative(currentFolder,targetFile);
30+
31+
functionrun(){
32+
try{
33+
symlinkSync(relativeTargetPath,relativeLinkPath);
34+
}catch(err){
35+
console.error(`Error creating symlink:${err.message}`);
36+
process.exit(1);
37+
}
38+
syncArgohubRedirectMap(targetFile,relativeLinkPath);
39+
console.info(
40+
`\x1b[32mSymlink created:\x1b[0m \x1b[34m${relativeLinkPath}\x1b[0m -> \x1b[33m${targetFile}\x1b[0m`
41+
);
42+
}
43+
44+
functionsyncArgohubRedirectMap(
45+
enterpriseCollectionPath,
46+
argoHubCollectionPath
47+
){
48+
constfilePath=join(
49+
__dirname,
50+
"../assets/js/src",
51+
"argohub-redirect-mapping.json"
52+
);
53+
constdata=readFileSync(filePath,"utf8");
54+
55+
constenterpriseDoc=transformPathToDocURL(enterpriseCollectionPath);
56+
constargohubDoc=transformPathToDocURL(argoHubCollectionPath);
57+
58+
constredirectMapping=JSON.parse(data);
59+
redirectMapping[enterpriseDoc]=argohubDoc;
60+
61+
constupdatedData=`${JSON.stringify(redirectMapping,null,2)}\n`;
62+
writeFileSync(filePath,updatedData,"utf8");
63+
64+
console.log(
65+
"The 'argohub-redirect-mapping.json' file has been updated successfully."
66+
);
67+
}
68+
69+
functiontransformPathToDocURL(path){
70+
returnpath.replace("_","/").replace(".md","/");
2971
}
3072

31-
console.info(
32-
`\x1b[32mSymlink created:\x1b[0m \x1b[34m${relativePath}\x1b[0m -> \x1b[33m${targetFile}\x1b[0m`
33-
);
73+
run();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp