Skip to content

Commit

Permalink
Clean up loop logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobo1 committed Jul 7, 2024
1 parent a3d27f4 commit 5379a2e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions atom_generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ function generateAtom(path: string): string {
// process html
const html: string = Fs.readFileSync(path, { encoding: 'utf8' });

let startIdx = html.indexOf('<h3 ');
while (startIdx >= 0) {
const endIdx = html.indexOf('<h3 ', (startIdx + 4));
const post = html.slice(startIdx, ((endIdx >= 0)
for (let endIdx = 0; endIdx >= 0; ) {
const startIdx = html.indexOf('<h3 ', endIdx);
endIdx = html.indexOf('<h3 ', (startIdx + 4));
const postEndIdx = ((endIdx >= 0)
? endIdx
: html.indexOf('</div>', (startIdx + 4)))); // don't include footer in the last post
startIdx = endIdx;
: html.indexOf('</div>', (startIdx + 4))); // don't include footer in the last post
const post = html.slice(startIdx, postEndIdx);

// parse
const $ = Cheerio.load(post, undefined, false);
Expand Down

0 comments on commit 5379a2e

Please sign in to comment.