Skip to content

Commit

Permalink
remove notes script added
Browse files Browse the repository at this point in the history
  • Loading branch information
wirednkod committed Apr 29, 2024
1 parent 1e8c393 commit 6204aae
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"scripts": {
"dev": "reveal-md ./ --watch --absolute-url http://localhost:1948",
"remove-notes": "node remove-notes.mjs --",
"help-rmd": "reveal-md --help",
"tag:cambridge": "git checkout tags/cambridge-2022 && yarn && yarn run build && mv build cambridge-2022&& git checkout main",
"tag:buenos-aires": "git checkout tags/buenos-aires-2023 && yarn && yarn run build && mv build buenos-aires-2023 && git checkout main",
Expand Down Expand Up @@ -51,4 +52,4 @@
"vite-plugin-svgr": "^4.2.0"
},
"packageManager": "[email protected]"
}
}
57 changes: 57 additions & 0 deletions remove-notes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import fs from 'fs';
import path from 'path';

async function removeMultilineSequences(directoryPath) {
try {
const files = await fs.promises.readdir(directoryPath);

for (const file of files) {
if ((await fs.promises.lstat(path.join(directoryPath, "/", file))).isDirectory()) {
removeMultilineSequences(path.join(directoryPath, "/", file))
} else {

const filePath = path.join(directoryPath, file);
const fileContent = await fs.promises.readFile(filePath, 'utf-8');
const modifiedContent = removeSequences(fileContent);

if (modifiedContent !== fileContent) {
await fs.promises.writeFile(filePath, modifiedContent);
console.log(`Modified: ${filePath}`);
} else {
console.log(`No modifications: ${filePath}`);
}
}

console.log('Processing complete.');
}
} catch (error) {
console.error('Error occurred:', error);
}
}

function removeSequences(content) {
const lines = content.split('\n');
let modifiedContent = '';
let isInsideSequence = false;

for (const line of lines) {
if (!isInsideSequence && line.trim().startsWith('Notes:')) {
isInsideSequence = true;
}

if (!isInsideSequence) {
modifiedContent += line + '\n';
}

if (isInsideSequence && (line.trim() === '---' || line.trim() === '---v')) {
isInsideSequence = false;
modifiedContent += line
}
}

return modifiedContent.trim();
}

// Example usage
const directoryPath = `syllabus/${process.argv[3]}`; // Replace this with your directory path
removeMultilineSequences(directoryPath);
3 changes: 1 addition & 2 deletions syllabus/2-Economics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ These are played with **real money on the line** and ends in an auction with tho

### Day 3 (0.25 day)

- Quiz

#### Morning
- Quiz

0 comments on commit 6204aae

Please sign in to comment.