Website: Add line number to edit page links on policies, queries and vitals pages. (#25965)
Changes: - Updated the `build-static-content` script to set a `lineNumberInYaml` value on queries, policies, and vitals. - Updated the edit page button on the policy-details, query-detail, and vital-details pages to take users to the specified query's line number in the YAML file.
This commit is contained in:
+22
-1
@@ -39,7 +39,7 @@ module.exports = {
|
||||
async()=>{// Parse queries.yml library (Informational queries and host vital queries) from YAML and prepare to bake them into the Sails app's configuration.
|
||||
let RELATIVE_PATH_TO_QUERY_LIBRARY_YML_IN_FLEET_REPO = 'docs/queries.yml';
|
||||
let yaml = await sails.helpers.fs.read(path.join(topLvlRepoPath, RELATIVE_PATH_TO_QUERY_LIBRARY_YML_IN_FLEET_REPO)).intercept('doesNotExist', (err)=>new Error(`Could not find standard query library YAML file at "${RELATIVE_PATH_TO_QUERY_LIBRARY_YML_IN_FLEET_REPO}". Was it accidentally moved? Raw error: `+err.message));
|
||||
|
||||
let linesInYamlFile = yaml.split('\n');
|
||||
let queriesWithProblematicDiscovery = [];
|
||||
let queriesWithProblematicContributors = [];
|
||||
let queriesWithProblematicTags = [];
|
||||
@@ -47,8 +47,19 @@ module.exports = {
|
||||
let query = yamlDocument.toJSON().spec;
|
||||
query.kind = yamlDocument.toJSON().kind;
|
||||
query.slug = _.kebabCase(query.name);// « unique slug to use for routing to this query's detail page
|
||||
|
||||
// Determine the line in the yaml that this query starts on.
|
||||
// this will allow us to link users directly to the query's position in the YAML file (currently >1500 lines) when users want to make a change.
|
||||
let lineWithTheQueriesNameKey = _.find(linesInYamlFile, (line)=>{
|
||||
return line.includes('name: '+query.name);
|
||||
});
|
||||
let lineNumberForEdittingThisQuery = linesInYamlFile.indexOf(lineWithTheQueriesNameKey);
|
||||
query.lineNumberInYaml = lineNumberForEdittingThisQuery; // Set the line number for edits.
|
||||
|
||||
// Remove the platform name from query names. This allows us to keep queries at their existing URLs while hiding them in the UI.
|
||||
query.name = query.name.replace(/\s\(macOS\)|\(Windows\)|\(Linux\)|\(Chrome\)|\(macOS\/Linux\)$/, '');
|
||||
|
||||
|
||||
if ((query.discovery !== undefined && !_.isString(query.discovery)) || (query.kind !== 'built-in' && _.isString(query.discovery))) {
|
||||
queriesWithProblematicDiscovery.push(query);
|
||||
}
|
||||
@@ -167,6 +178,7 @@ module.exports = {
|
||||
let RELATIVE_PATH_TO_POLICY_LIBRARY_YML_IN_FLEET_REPO = 'docs/01-Using-Fleet/standard-query-library/standard-query-library.yml';
|
||||
// let RELATIVE_PATH_TO_QUERY_LIBRARY_YML_IN_FLEET_REPO = 'docs/queries.yml';
|
||||
let yaml = await sails.helpers.fs.read(path.join(topLvlRepoPath, RELATIVE_PATH_TO_POLICY_LIBRARY_YML_IN_FLEET_REPO)).intercept('doesNotExist', (err)=>new Error(`Could not find standard query library YAML file at "${RELATIVE_PATH_TO_POLICY_LIBRARY_YML_IN_FLEET_REPO}". Was it accidentally moved? Raw error: `+err.message));
|
||||
let linesInYamlFile = yaml.split('\n');
|
||||
let queriesWithProblematicResolutions = [];
|
||||
let queriesWithProblematicContributors = [];
|
||||
let queriesWithProblematicTags = [];
|
||||
@@ -177,6 +189,15 @@ module.exports = {
|
||||
if(query.kind === 'query'){
|
||||
return undefined;
|
||||
}
|
||||
// Determine the line in the yaml that this query starts on.
|
||||
// this will allow us to link users directly to the query's position in the YAML file (currently >1500 lines) when users want to make a change.
|
||||
let lineWithTheQueriesNameKey = _.find(linesInYamlFile, (line)=>{
|
||||
return line.includes('name: '+query.name);
|
||||
});
|
||||
let lineNumberForEdittingThisQuery = linesInYamlFile.indexOf(lineWithTheQueriesNameKey);
|
||||
query.lineNumberInYaml = lineNumberForEdittingThisQuery; // Set the line number for edits.
|
||||
|
||||
|
||||
query.slug = _.kebabCase(query.name);// « unique slug to use for routing to this query's detail page
|
||||
// Remove the platform name from query names. This allows us to keep queries at their existing URLs while hiding them in the UI.
|
||||
query.name = query.name.replace(/\s\(macOS\)|\(Windows\)|\(Linux\)$/, '');
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@
|
||||
<a href="/docs">Docs</a>
|
||||
<a href="/docs/rest-api">REST API</a>
|
||||
<a href="/guides">Guides</a>
|
||||
<a purpose="edit-button" class="d-flex align-items-center text-nowrap" target="_blank" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath"><img alt="A pencil icon" src="/images/pencil-16x16@2x.png">Edit page</a>
|
||||
<a purpose="edit-button" class="d-flex align-items-center text-nowrap" target="_blank" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath+'#L'+policy.lineNumberInYaml"><img alt="A pencil icon" src="/images/pencil-16x16@2x.png">Edit page</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Vendored
+2
-1
@@ -52,7 +52,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div purpose="docs-links" class="order-3">
|
||||
<a purpose="sidebar-link" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath"> <img src="/images/icon-edit-16x16@2x.png" alt="Suggest an edit">Edit</a>
|
||||
<a purpose="sidebar-link" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath+'#L'+query.lineNumberInYaml"> <img src="/images/icon-edit-16x16@2x.png" alt="Suggest an edit">Edit</a>
|
||||
<a purpose="sidebar-link" href="/contact"><img alt="Talk to an engineer" src="/images/icon-contact-16x16@2x.png">Talk to us</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@
|
||||
</div>
|
||||
<% } %>
|
||||
<div purpose="edit-button-container">
|
||||
<a purpose="edit-button" class="d-flex align-items-center text-nowrap" target="_blank" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath">Suggest an edit <img src="/images/icon-external-link-13x13@2x.png" alt="external link"></a>
|
||||
<a purpose="edit-button" class="d-flex align-items-center text-nowrap" target="_blank" :href="'https://github.com/fleetdm/fleet/edit/main/'+queryLibraryYmlRepoPath+'#L'+thisVital.lineNumberInYaml">Suggest an edit <img src="/images/icon-external-link-13x13@2x.png" alt="external link"></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user