-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
3 deletions.
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 |
---|---|---|
|
@@ -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", | ||
|
@@ -51,4 +52,4 @@ | |
"vite-plugin-svgr": "^4.2.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} | ||
} |
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,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); |
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