Skip to content

Commit

Permalink
Merge pull request #2994 from spryker/DEV-SDK-SEO-Update
Browse files Browse the repository at this point in the history
Dev SDK SEO Update
  • Loading branch information
andriitserkovnyi authored Jan 6, 2025
2 parents 6b99a20 + 2c1f1ab commit 882cae9
Show file tree
Hide file tree
Showing 81 changed files with 502 additions and 344 deletions.
11 changes: 7 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ commonOptions = {
/twitter.com\/[\.\w\-\/\?]+/,
/www.optimise-it.de\/[\.\w\-\/\?]+/,
/blackfire.io\/[\.\w\-\/\?]+/,
/www.cdata.com/virtuality\/[\.\w\-\/\?]+/,
/dixa.com\/[\.\w\-\/\?]+/,
/rxjs.dev\/[\.\w\-\/\?]+/,
/www.blackfire.io\/[\.\w\-\/\?]+/,
Expand All @@ -96,10 +97,12 @@ commonOptions = {
/code.visualstudio.com\/[\.\w\-\/\?]+/,
/www.jetbrains.com\/[\.\w\-\/\?]+/,
/docs.spring.io\/[\.\w\-\/\?]+/,
"http://redisdesktop.com/",
"https://developer.computop.com/display/EN/Test+Cards",
"https://www.centralbank.cy/",
"https://www.facebook.com/Spryker/"
/redisdesktop.com\/[\.\w\-\/\?]+/,
/developer.computop.com/display/EN/Test+Cards\/[\.\w\-\/\?]+/,
/www.centralbank.cy\/[\.\w\-\/\?]+/,
/dashboard.algolia.com/\/[\.\w\-\/\?]+/,
/www.facebook.com/Spryker\/[\.\w\-\/\?]+/
],
:ignore_files => [],
:typhoeus => {
Expand Down
136 changes: 136 additions & 0 deletions _scripts/heading_level_checker/heading_level_checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

function fixHeadings(content) {
// Parse frontmatter
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
if (!fmMatch) return { content, changes: 0 };

const frontmatter = fmMatch[1];
const title = frontmatter.match(/title:\s*(.*)/)?.[1];
if (!title) return { content: content, changes: 0 };

// Get the content after frontmatter
const body = content.slice(fmMatch[0].length);

// Find all heading levels in the content (excluding code blocks)
const lines = body.split('\n');
let inCodeBlock = false;
const headingLevels = [];

lines.forEach(line => {
if (line.trim().startsWith('```')) {
inCodeBlock = !inCodeBlock;
return;
}
if (inCodeBlock) return;

const headingMatch = line.match(/^(#{1,6}) /);
if (headingMatch) {
headingLevels.push(headingMatch[1].length);
}
});

if (headingLevels.length === 0) return { content: content, changes: 0 };

// Find the highest level (minimum number of #)
const highestLevel = Math.min(...headingLevels);

// Calculate how many levels to shift to make highest level H2
const levelShift = 2 - highestLevel;

// If no shift needed (highest level is already H2), return unchanged
if (levelShift === 0) return { content: content, changes: 0 };

// Apply the shift to all headings while preserving code blocks
let changes = 0;
inCodeBlock = false;
const fixedLines = lines.map(line => {
if (line.trim().startsWith('```')) {
inCodeBlock = !inCodeBlock;
return line;
}
if (inCodeBlock) return line;

const headingMatch = line.match(/^(#{1,6}) (.*)/);
if (headingMatch) {
const newLevel = Math.max(1, Math.min(6, headingMatch[1].length + levelShift));
changes++;
return `${'#'.repeat(newLevel)} ${headingMatch[2]}`;
}
return line;
});

return {
content: `---\n${frontmatter}\n---${fixedLines.join('\n')}`,
changes: changes
};
}

function findMarkdownFiles(dir) {
let results = [];
const files = fs.readdirSync(dir);

for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory()) {
results = results.concat(findMarkdownFiles(filePath));
} else if (file.endsWith('.md')) {
results.push(filePath);
}
}

return results;
}

function processFile(filePath, stats) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const result = fixHeadings(content);
stats.totalFiles++;

if (result.changes > 0) {
fs.writeFileSync(filePath, result.content);
console.log(`Processed ${filePath} - ${result.changes} heading(s) adjusted`);
stats.filesChanged++;
stats.totalHeadingsAdjusted += result.changes;
} else {
console.log(`Processed ${filePath} - no changes needed (headings already correct)`);
}
} catch (err) {
console.error(`Error processing ${filePath}:`, err);
}
}

// Get command line arguments
const args = process.argv.slice(2);

// If no arguments provided, process all .md files in /docs/
let filesToProcess;

if (args.length === 0) {
console.log('No files specified, processing all .md files in /docs/...\n');
filesToProcess = findMarkdownFiles('docs');
} else {
filesToProcess = args;
}

// Initialize statistics
const stats = {
totalFiles: 0,
filesChanged: 0,
totalHeadingsAdjusted: 0
};

// Process all files
filesToProcess.forEach(file => processFile(file, stats));

// Print detailed summary
console.log('\nSummary:');
console.log(`Total files checked: ${stats.totalFiles}`);
console.log(`Files that needed changes: ${stats.filesChanged}`);
console.log(`Total headings adjusted: ${stats.totalHeadingsAdjusted}`);
19 changes: 19 additions & 0 deletions _scripts/heading_level_checker/run_heading_level_checker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The heading level checker checks and corrects headings according to the standard convention. The standard hierarchy of headings in a document body is h2>h3>h4. h1 is a document's title, which is part of the front matter. The script checks and shifts the highest-level heading to be h2. Then it shifts the other headings to follow the hierarchy.

Run the checker in the `docs` folder:

```bash
node _scripts/heading_level_checker/heading_level_checker.js
```

Run the checker for a particular file or folder:

```bash
node _scripts/heading_level_checker/heading_level_checker.js {PATH_TO_FILE}
```

Example of a targeted run:

```bash
node _scripts/heading_level_checker/heading_level_checker.js docs/dg/dev/guidelines/coding-guidelines
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This document describes how to customize deployment pipelines.
{% endinfo_block %}


### Adding a single command to a deployment pipeline
## Adding a single command to a deployment pipeline

To customize the `pre-deploy` stage of a pipeline:

Expand All @@ -46,7 +46,7 @@ image:

During the next deployment, the command will be executed in the `pre-deploy` stage.

### Adding multiple commands to a deployment pipeline via a shell script
## Adding multiple commands to a deployment pipeline via a shell script

To add multiple commands to the `pre-deploy` stage:

Expand All @@ -70,7 +70,7 @@ Do not include the `.yml` extension of the file name in `{path_to_script}`. For

During the next deployment, the commands in the script will be executed in the `pre-deploy` stage.

### Adding different commands for different environments and pipeline types
## Adding different commands for different environments and pipeline types

By default, in `pre-deploy` and `post-deploy` stages, there is no possibility to run different commands for combinations of different environments and pipeline types. To do that, you can set up a custom shell script with _if statements_.

Expand All @@ -94,7 +94,7 @@ if [ "${SPRYKER_PIPELINE_TYPE}" == "destructive" ]; then
fi
```

### Adding commands to the install stage of deployment pipelines
## Adding commands to the install stage of deployment pipelines

To add one or more commands to the `install` stage of a deployment pipeline:

Expand Down
Loading

0 comments on commit 882cae9

Please sign in to comment.