Skip to content

Commit

Permalink
Merge pull request #27 from vtexdocs/add-delete-markdown-files-function
Browse files Browse the repository at this point in the history
feat: make all scripts run from index.js
  • Loading branch information
julia-rabello authored Sep 4, 2024
2 parents 7c0680d + e57e403 commit 70af0e8
Show file tree
Hide file tree
Showing 1,294 changed files with 3,160 additions and 2,013 deletions.
95 changes: 48 additions & 47 deletions docs-utils/fix-callouts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require('fs');
const fs = require('fs').promises;
const path = require('path');

// The root folder to process
const rootFolder = 'docs';

// Maximum number of files to process simultaneously
const MAX_CONCURRENT_FILES = 100; // Adjust this based on your system's limit
const MAX_CONCURRENT_FILES = 100;

// Array to keep track of currently processing files
let activeFiles = 0;
Expand Down Expand Up @@ -65,58 +65,59 @@ function convertCallout(htmlCallout) {
return markdownCallout;
}

// Function to process each markdown file
function processFile(filePath) {
// Function to process each Markdown file
async function processFile(filePath) {
activeFiles++;

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) throw err;

try {
const data = await fs.readFile(filePath, 'utf8');
// Replace HTML structures with corresponding markdown symbols
const newData = data
.replace(/<div\s+class\s*=\s*"alert alert-info">(.*?)<\/div>/gs, (match, p1) => `>ℹ️ ${convertCallout(p1)}`)
.replace(/<div\s+class\s*=\s*"alert alert-warning">(.*?)<\/div>/gs, (match, p1) => `>⚠️ ${convertCallout(p1)}`)
.replace(/<div\s+class\s*=\s*"alert alert-danger">(.*?)<\/div>/gs, (match, p1) => `>❗ ${convertCallout(p1)}`);

// Write the modified content back to the file
fs.writeFile(filePath, newData, 'utf8', (err) => {
if (err) throw err;
console.log(`Processed file: ${filePath}`);
activeFiles--;

// Process the next file in the queue if available
if (fileQueue.length > 0) {
const nextFile = fileQueue.shift();
processFile(nextFile);
}
});
});
.replace(/<div\s+[^>]*class\s*=\s*"alert alert-info"[^>]*>(.*?)<\/div>/gs, (match, p1) => `>ℹ️ ${convertCallout(p1)}`)
.replace(/<div\s+[^>]*class\s*=\s*"alert alert-warning"[^>]*>(.*?)<\/div>/gs, (match, p1) => `>⚠️ ${convertCallout(p1)}`)
.replace(/<div\s+[^>]*class\s*=\s*"alert alert-danger"[^>]*>(.*?)<\/div>/gs, (match, p1) => `>❗ ${convertCallout(p1)}`);

await fs.writeFile(filePath, newData, 'utf8');
} catch (err) {
console.error(`Error processing file: ${filePath}`, err);
} finally {
activeFiles--;
if (fileQueue.length > 0) {
const nextFile = fileQueue.shift();
processFile(nextFile);
}
}
}

// Recursive function to process all markdown files in the directory
function processDirectory(directory) {
fs.readdir(directory, (err, files) => {
if (err) throw err;

files.forEach(file => {
async function processDirectory(directory) {
try {
const files = await fs.readdir(directory);
for (const file of files) {
const filePath = path.join(directory, file);
fs.stat(filePath, (err, stats) => {
if (err) throw err;

if (stats.isDirectory()) {
// Recursively process subdirectories
processDirectory(filePath);
} else if (path.extname(file) === '.md') {
if (activeFiles < MAX_CONCURRENT_FILES) {
processFile(filePath);
} else {
fileQueue.push(filePath);
}
const stats = await fs.stat(filePath);

if (stats.isDirectory()) {
await processDirectory(filePath);
} else if (path.extname(file) === '.md') {
if (activeFiles < MAX_CONCURRENT_FILES) {
processFile(filePath);
} else {
fileQueue.push(filePath);
}
});
});
});
}
}
} catch (err) {
console.error(`Error processing directory: ${directory}`, err);
}
}

async function fixCallouts() {
console.log("Fixing callouts...");
await processDirectory(rootFolder);
while (activeFiles > 0 || fileQueue.length > 0) {
await new Promise(resolve => setTimeout(resolve, 100));
}
console.log("Finished fixing callouts in markdown files.");
}

// Start processing from the root folder
processDirectory(rootFolder);
module.exports = { fixCallouts };
146 changes: 81 additions & 65 deletions docs-utils/replace-quotes.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,98 @@
const fs = require('fs');
const fs = require('fs').promises;
const path = require('path');

// Path to the 'docs' directory
const docsDir = path.resolve(__dirname, '../docs');
const MAX_CONCURRENT_FILES = 100;

let activeFiles = 0;
let fileQueue = [];

// Function to process each Markdown file
const processFile = (filePath) => {
const data = fs.readFileSync(filePath, 'utf8');
const lines = data.split('\n');
async function processFile(filePath) {
try {
const data = await fs.readFile(filePath, 'utf8');
const lines = data.split('\n');

if (lines[1] && lines[1].startsWith('title:')) {
let titleLine = lines[1].trim();
const titleContentMatch = titleLine.match(/^title:\s*(['"])(.*)\1$/);

if (lines[1] && lines[1].startsWith('title:')) {
let titleLine = lines[1].trim();
const titleContentMatch = titleLine.match(/^title:\s*(['"])(.*)\1$/);
if (titleContentMatch) {
const currentOuterQuote = titleContentMatch[1];
const originalTitleContent = titleContentMatch[2];
let updatedTitleContent;
let updatedTitleLine;

if (titleContentMatch) {
const currentOuterQuote = titleContentMatch[1];
const originalTitleContent = titleContentMatch[2];
let updatedTitleContent;
let updatedTitleLine;
if (currentOuterQuote === `'`) {
if (originalTitleContent.includes('"')) {
updatedTitleContent = originalTitleContent.replace(/"/g, "'");
updatedTitleLine = `title: "${updatedTitleContent}"`;
} else {
updatedTitleLine = titleLine;
}
} else if (currentOuterQuote === `"`) {
if (originalTitleContent.includes('"')) {
updatedTitleContent = originalTitleContent.replace(/"(?![^"]*")/g, "'");
updatedTitleLine = `title: "${updatedTitleContent}"`;
} else {
updatedTitleLine = titleLine;
}
}

if (currentOuterQuote === `'`) {
// Outer quotes are single
if (originalTitleContent.includes('"')) {
// Inner double quotes present
updatedTitleContent = originalTitleContent.replace(/"/g, "'");
updatedTitleLine = `title: "${updatedTitleContent}"`;
} else {
// No inner double quotes
updatedTitleLine = titleLine;
if (updatedTitleLine && updatedTitleLine !== titleLine) {
lines[1] = updatedTitleLine;
const newData = lines.join('\n');
await fs.writeFile(filePath, newData, 'utf8');
// console.log(`Quotes replaced in file: ${filePath}`);
}
}
}
} else if (currentOuterQuote === `"`) {
// Outer quotes are double
if (originalTitleContent.includes('"')) {
// Inner double quotes present
updatedTitleContent = originalTitleContent.replace(/"(?![^"]*")/g, "'");
updatedTitleLine = `title: "${updatedTitleContent}"`;
} else {
// No inner double quotes
updatedTitleLine = titleLine;
} catch (error) {
console.error(`Error processing file: ${filePath}`, error);
} finally {
activeFiles--;
if (fileQueue.length > 0) {
const nextFile = fileQueue.shift();
processFile(nextFile);
}
}

// Only update if necessary
if (updatedTitleLine && updatedTitleLine !== titleLine) {
lines[1] = updatedTitleLine;
const newData = lines.join('\n');
fs.writeFileSync(filePath, newData, 'utf8');
console.log(`Updated file: ${filePath}`);
}
}
}
};
}

// Function to recursively process files in directories
const processDirectory = (dirPath) => {
fs.readdir(dirPath, (err, files) => {
if (err) {
console.error('Unable to scan directory:', err);
return;
}
async function processDirectory(dirPath) {
try {
const files = await fs.readdir(dirPath);

for (const file of files) {
const filePath = path.join(dirPath, file);
const stats = await fs.stat(filePath);

files.forEach((file) => {
const filePath = path.join(dirPath, file);
fs.stat(filePath, (err, stats) => {
if (err) {
console.error('Unable to stat file:', err);
return;
if (stats.isDirectory()) {
await processDirectory(filePath);
} else if (path.extname(file) === '.md') {
if (activeFiles < MAX_CONCURRENT_FILES) {
activeFiles++;
processFile(filePath);
} else {
fileQueue.push(filePath);
}
}
}
} catch (error) {
console.error('Error processing directory:', error);
}
}

if (stats.isDirectory()) {
processDirectory(filePath);
} else if (path.extname(file) === '.md') {
processFile(filePath);
}
});
});
});
};
async function replaceQuotes() {
console.log("Replacing quotation marks...");
await processDirectory(docsDir);

// Wait until all files are processed
while (activeFiles > 0 || fileQueue.length > 0) {
await new Promise(resolve => setTimeout(resolve, 100));
}

console.log("Finished replacing quotation marks in markdown files.");
}

// Start processing from the docs directory
processDirectory(docsDir);
module.exports = { replaceQuotes };
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The product integration flow on the Via Varejo Marketplace was [modified in thei

There was no need for mapping to activate the Via Varejo Integration before this change. Mapping categories, variations and attributes for your products is henceforth __mandatory__.

<div class="alert alert-warning" role="alert"><strong>Attention:</strong> Products created or updated after this change will only be integrated if their category, variations and attributes are mapped out.</div>
>⚠️ **Attention:** Products created or updated after this change will only be integrated if their category, variations and attributes are mapped out.
## Why did we make this change?

Expand All @@ -36,4 +36,4 @@ To ensure the best positioning and experience for our clients in the certified m

Map categories, variations and attributes according to our [documentation](https://help.vtex.com/en/tracks/configurar-integracao-da-via-varejo--3E9XylGaJ2wqwISGyw4GuY/5QVZFYNfuRIQKdq34MbTxz#fazendo-o-upload).

<div class="alert alert-info" role="alert">This process can be performed gradually according to your needs and only needs to be done once per category. Once a category and its variations/attributes are mapped, all products in that category will be integrated normally without requiring any additional action.</div>
>ℹ️ This process can be performed gradually according to your needs and only needs to be done once per category. Once a category and its variations/attributes are mapped, all products in that category will be integrated normally without requiring any additional action.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Nowadays, consumers seek diversity and ease of payments, and it is essential to

That's why VTEX entered into a partnership with Lendico, which launched the installments loans function, aiming to democratize purchasing power and contribute exponentially to increase your sales.

<div class="alert alert-info" role="alert">This payment option is only available in Brazil.</div>
>ℹ️ This payment option is only available in Brazil.
## Who is Lendico?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ announcementSynopsisEN: 'This is a regional exclusive content not applicable to
---


<div class="alert alert-warning" role="alert">This is a regional exclusive content not applicable to English speaking countries.</div>
>⚠️ This is a regional exclusive content not applicable to English speaking countries.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ The new menu provides significant advantages, which are highlighted below:
- **Intuitive navigation:** Improved layout to quickly find what you need.
- **Visual consistency:** Consistent look and feel aligned with other recent platform updates.

<img src="//images.ctfassets.net/alneenqid6w5/pcXNfExZYZML7AHP57tzz/42794337b88dd86f325eb5e034d44f1f/image.png" alt= “menu-sales-app-en” width="35%" height="35%">
<img src="https://images.ctfassets.net/alneenqid6w5/pcXNfExZYZML7AHP57tzz/42794337b88dd86f325eb5e034d44f1f/image.png" alt= “menu-sales-app-en” width="35%" height="35%">

### Offers section

The Offers section allows merchants to display specific products or search results and customize their marketing strategies to their business needs and goals.

One of the key features of this update is that merchants can set the Offers section as their home page. This provides a more customized user experience, as customers are immediately greeted with selected content and product recommendations. Learn more in the [Enabling Local stock sale in VTEX Sales App](https://help.vtex.com/en/tutorial/enabling-local-stock-sale-in-vtex-sales-app--54eQN4rOH5yBYPGG2w8v9q) article.

<img src="//images.ctfassets.net/alneenqid6w5/XXJQykcV9p6yNN6Q5mB5u/fcdfa190f4766760449d9bf4d7eff4b5/image.png" alt= “anuncio-sale-app-en” width="35%" height="35%">
<img src="https://images.ctfassets.net/alneenqid6w5/XXJQykcV9p6yNN6Q5mB5u/fcdfa190f4766760449d9bf4d7eff4b5/image.png" alt= “anuncio-sale-app-en” width="35%" height="35%">

### Sales Performance

The Sales Performance page allows merchants to view their sales metrics and compare performance across sales dates and staff performance. Learn more in the [VTEX Sales App: Sales Performance](https://help.vtex.com/en/tutorial/sales-app-sales-performance--7i4Elt835tatBM6iqZoc56) article.

<img src="//images.ctfassets.net/alneenqid6w5/3UWhX6QODOG8pQ6Xi0QXKV/0f05e6e637790f140f22bb5b9bf877e5/image.png" alt= “vendas-da-loja-sales-app-en” width="35%" height="35%">
<img src="https://images.ctfassets.net/alneenqid6w5/3UWhX6QODOG8pQ6Xi0QXKV/0f05e6e637790f140f22bb5b9bf877e5/image.png" alt= “vendas-da-loja-sales-app-en” width="35%" height="35%">

## What needs to be done?

Expand Down
Loading

0 comments on commit 70af0e8

Please sign in to comment.