Last active
March 26, 2024 19:52
-
-
Save AhmedMohamedAbdelaty/75581e9803e07565aaa02c216a81bb26 to your computer and use it in GitHub Desktop.
Add Time of each section next to the title, using regex to select the line from the file
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
import { readFileSync, writeFileSync } from "fs"; | |
function editFile(filePath, time) { | |
const fileContent = readFileSync(filePath, "utf8").split("\n"); | |
let counter = 0; | |
for (let i = 0; i < fileContent.length; i++) { | |
const line = fileContent[i]; | |
if (line.match(/^- \[ \] Section \d+: \w+/)) { | |
fileContent[i] = `${line} (${time[counter]})`; | |
counter++; | |
} | |
} | |
writeFileSync(filePath, fileContent.join("\n")); | |
} | |
function readAllLines(filePath) { | |
const fileContent = readFileSync(filePath, "utf8").split("\n"); | |
const time = []; | |
for (let i = 0; i < fileContent.length; i++) { | |
time.push(fileContent[i]); | |
} | |
return time; | |
} | |
const time = readAllLines("/home/ahmed/Desktop/data.txt"); | |
const markdownFile = | |
"/media/ahmed/Ahmed/Important Stuff/Ahmed-Notes/Carrer/Front-End/JS-Course/JavaScript Course.md"; | |
editFile(markdownFile, time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment