-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC-305: orphan pages detector #428
Draft
fantkolja
wants to merge
55
commits into
hazelcast:main
Choose a base branch
from
fantkolja:feature/doc-305-orphan-pages-detector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
a628b9d
latest supported platform
fantkolja fbbca51
include version branches
fantkolja ddbf816
include version branches
fantkolja 0e16ef5
include version branches
fantkolja e68fc68
include version branches
fantkolja 72d8482
correct 5.5. version MC
fantkolja 40ddbe9
correct 5.5. version MC
fantkolja b46319d
Merge branch 'hazelcast:main' into main
fantkolja aba5cb0
Merge branch 'hazelcast:main' into main
fantkolja b935a50
Merge branch 'hazelcast:main' into main
fantkolja 603c385
Merge branch 'hazelcast:main' into main
fantkolja 4dabc73
Merge branch 'hazelcast:main' into main
fantkolja 4a32a17
Merge remote-tracking branch 'upstream/main'
fantkolja 54d09c7
Merge remote-tracking branch 'upstream/main'
fantkolja b2aee57
Merge remote-tracking branch 'upstream/main'
fantkolja d9615c5
Merge remote-tracking branch 'upstream/main'
fantkolja e62a1ce
add orphan pages checker
fantkolja c8f45ff
add orphan pages checker
fantkolja 7dd4020
copy scripts from hazelcast-docs
fantkolja 040d05a
copy scripts from hazelcast-docs
fantkolja fed0d90
copy scripts from hazelcast-docs
fantkolja 6471231
copy scripts from hazelcast-docs
fantkolja 96af6ac
copy scripts from hazelcast-docs
fantkolja d7a45a8
copy scripts from hazelcast-docs
fantkolja c529c48
copy scripts from hazelcast-docs
fantkolja aed3bc2
copy scripts from hazelcast-docs
fantkolja 1ef1bb0
copy scripts from hazelcast-docs
fantkolja bb9fb5c
copy scripts from hazelcast-docs
fantkolja 4ed9964
copy scripts from hazelcast-docs
fantkolja c666e6b
copy scripts from hazelcast-docs
fantkolja 4031d9e
copy scripts from hazelcast-docs
fantkolja 7e3ef16
copy scripts from hazelcast-docs
fantkolja 3859dc8
copy scripts from hazelcast-docs
fantkolja 15c0e2a
copy scripts from hazelcast-docs
fantkolja 2c519ff
copy scripts from hazelcast-docs
fantkolja 563b83d
copy scripts from hazelcast-docs
fantkolja 3fb35e0
copy scripts from hazelcast-docs
fantkolja 51b64a7
copy scripts from hazelcast-docs
fantkolja 6fb951b
copy scripts from hazelcast-docs
fantkolja 5325e9c
copy scripts from hazelcast-docs
fantkolja e34e6cc
copy scripts from hazelcast-docs
fantkolja 5bbeb46
copy scripts from hazelcast-docs
fantkolja 200532c
copy scripts from hazelcast-docs
fantkolja aa1a434
copy scripts from hazelcast-docs
fantkolja 3a8de6f
copy scripts from hazelcast-docs
fantkolja 0c5b00f
copy scripts from hazelcast-docs
fantkolja 9e70daf
copy scripts from hazelcast-docs
fantkolja 257499e
copy scripts from hazelcast-docs
fantkolja 8dcd407
copy scripts from hazelcast-docs
fantkolja 93ac0c7
copy scripts from hazelcast-docs
fantkolja 1b88863
copy scripts from hazelcast-docs
fantkolja f66f682
copy scripts from hazelcast-docs
fantkolja 88a8191
copy scripts from hazelcast-docs
fantkolja 2f892ae
copy scripts from hazelcast-docs
fantkolja 7d7acf1
copy scripts from hazelcast-docs
fantkolja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ jobs: | |
uses: actions/checkout@v4 | ||
- name: Check dead links | ||
uses: hazelcast/hazelcast-docs/.github/actions/validate@main | ||
- name: Check orphan pages | ||
shell: bash | ||
run: npm run check-orphan-pages | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to install a specific version of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// @TODO: if we go with this approach, we DEFINITELY need an npm package | ||
// containing all our helper extensions and scripts | ||
// it can be just a single package (e.g. "hazelcast-antora-helpers") to simplify things | ||
// the scripts can be then imported like `const { checkOrphanLinks } = require('hazelcast-antora-helpers');` | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
class NavLinksCollector { | ||
static FILE_LINK_REGEXP = /xref:([\w,\s-]+:)?([\w,\s-]+.adoc)/; | ||
static CHILD_NAV_REGEXP = /include::([\w,\s-]+):partial\$nav.adoc/; | ||
|
||
// @TODO: use hashmap or dictionary to optimize | ||
nav = []; | ||
|
||
constructor(rootNavUrl) { | ||
this.nav = this.readNavFile(rootNavUrl, 'ROOT'); | ||
} | ||
|
||
/** | ||
* | ||
* @param filename - name of the .adoc file | ||
* @param urlModule - the part of the URL in the nav file before filename. It can be a module name or blank. | ||
* if it's blank, it means that antora builder will look up the page in twp places: | ||
* in "ROOT" or in the current module | ||
* @param navModule - the directory name of the current nav.adoc file | ||
* @returns {String[]} - Strings with page URLs | ||
*/ | ||
static buildFileUrl(filename, urlModule, navModule) { | ||
const result = []; | ||
if (urlModule) { | ||
result.push(path.join('docs', 'modules', urlModule, 'pages', filename)); | ||
} else { | ||
// check if there is no urlModule, then it means, that the page can either be in "ROOT" or in the current module | ||
// that's why we are adding both possibilities to the list | ||
if (navModule !== 'ROOT') { | ||
result.push(path.join('docs', 'modules', 'ROOT', 'pages', filename)); | ||
} | ||
result.push(path.join('docs', 'modules', navModule, 'pages', filename)); | ||
} | ||
return result; | ||
} | ||
|
||
static buildChildNavUrl( navModule) { | ||
// check if module is NULL, then use navModule instead | ||
return `./docs/modules/${navModule}/partials/nav.adoc`; | ||
} | ||
|
||
readNavFile(url, navModule) { | ||
const nav = []; | ||
try { | ||
const lines = fs.readFileSync(url, 'utf-8').split('\n'); | ||
|
||
for (const line of lines) { | ||
const match = line.match(NavLinksCollector.FILE_LINK_REGEXP); | ||
if (match) { | ||
const filename = match[2]; | ||
// trim the ending ":" | ||
const fileModule = match[1]?.slice(0, -1); | ||
nav.push(...NavLinksCollector.buildFileUrl(filename, fileModule, navModule)); | ||
} else if (NavLinksCollector.CHILD_NAV_REGEXP.test(line)) { | ||
const match = line.match(NavLinksCollector.CHILD_NAV_REGEXP); | ||
const childNavModule = match[1]; | ||
const childNav = this.readNavFile(NavLinksCollector.buildChildNavUrl(childNavModule), childNavModule); | ||
nav.push(...childNav); | ||
} | ||
} | ||
|
||
} catch (err) { | ||
console.error(err); | ||
} | ||
return nav; | ||
} | ||
} | ||
|
||
function iteratePageFiles(navPages) { | ||
const orphanPages = []; | ||
const rootDir = path.join('docs', 'modules'); | ||
fs.readdirSync(rootDir).forEach((moduleDir) => { | ||
const moduleUrl = path.join(rootDir, moduleDir); | ||
if (fs.statSync(moduleUrl).isDirectory()) { | ||
fs.readdirSync(path.join(moduleUrl, 'pages')).forEach((file) => { | ||
const fileUrl = path.join(moduleUrl, 'pages', file); | ||
if (!navPages.includes(fileUrl)) { | ||
orphanPages.push(fileUrl); | ||
} | ||
}); | ||
} | ||
}); | ||
return orphanPages; | ||
} | ||
|
||
function main() { | ||
// 1. Parse nav files and create a depth-first-traversal array of the page file links | ||
const linksCollector = new NavLinksCollector('./docs/modules/ROOT/nav.adoc'); | ||
// 2. Iterate recursively over all {module}/pages and lookup it in the navigation tree | ||
const orphanPages = iteratePageFiles(linksCollector.nav); | ||
|
||
if (orphanPages.length === 0) { | ||
console.log('No orphan pages detected. YAY!'); | ||
} else { | ||
console.warn('The following orphan pages were detected:'); | ||
console.warn(orphanPages); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - not sure if neccesary.