-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bde9130
commit ae249c0
Showing
12 changed files
with
177 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"osrs-web-scraper": minor | ||
--- | ||
|
||
Add transformer for converting single line bold text to header-3 |
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,5 @@ | ||
--- | ||
"osrs-web-scraper": minor | ||
--- | ||
|
||
Add transformer for combining consecutive MediaWikiBreak's |
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
14 changes: 14 additions & 0 deletions
14
src/scrapers/news/transformers/__tests__/__snapshots__/headerTransformer.test.ts.snap
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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NewsHeaderTransformer should change bold text to header-3 1`] = ` | ||
"__TOC__ | ||
===You can also discuss this update on our=== | ||
''The Old School Team.''" | ||
`; | ||
|
||
exports[`NewsHeaderTransformer should not change bold text to header-3 1`] = ` | ||
"__TOC__ | ||
'''test''' | ||
''The Old School Team.''" | ||
`; |
6 changes: 5 additions & 1 deletion
6
src/scrapers/news/transformers/__tests__/__snapshots__/imageCaptionTransformer.test.ts.snap
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
24 changes: 24 additions & 0 deletions
24
src/scrapers/news/transformers/__tests__/breakTransformer.ts
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,24 @@ | ||
import { | ||
MediaWikiBreak, | ||
MediaWikiBuilder, | ||
MediaWikiContent, | ||
MediaWikiText, | ||
MediaWikiTOC, | ||
} from "../../../../utils/mediawiki"; | ||
import NewsBreakTransformer from "../breakTransformer"; | ||
|
||
describe("NewsBreakTransformer", () => { | ||
it("should combine three lines breaks to one", () => { | ||
const originalContent: MediaWikiContent[] = [ | ||
new MediaWikiTOC(), | ||
new MediaWikiBreak(), | ||
new MediaWikiBreak(), | ||
new MediaWikiBreak(), | ||
new MediaWikiText("The Old School Team.", { italics: true }), | ||
]; | ||
const transformed = new NewsBreakTransformer().transform(originalContent); | ||
expect( | ||
new MediaWikiBuilder().addContents(transformed).build() | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/scrapers/news/transformers/__tests__/headerTransformer.test.ts
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,39 @@ | ||
import { | ||
MediaWikiBreak, | ||
MediaWikiBuilder, | ||
MediaWikiContent, | ||
MediaWikiText, | ||
MediaWikiTOC, | ||
} from "../../../../utils/mediawiki"; | ||
import NewsHeaderTransformer from "../headerTransformer"; | ||
|
||
describe("NewsHeaderTransformer", () => { | ||
it("should change bold text to header-3", () => { | ||
const originalContent: MediaWikiContent[] = [ | ||
new MediaWikiTOC(), | ||
new MediaWikiBreak(), | ||
new MediaWikiText("You can also discuss this update on our", { | ||
bold: true, | ||
}), | ||
new MediaWikiBreak(), | ||
new MediaWikiText("The Old School Team.", { italics: true }), | ||
]; | ||
const transformed = new NewsHeaderTransformer().transform(originalContent); | ||
expect( | ||
new MediaWikiBuilder().addContents(transformed).build() | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it("should not change bold text to header-3", () => { | ||
const originalContent: MediaWikiContent[] = [ | ||
new MediaWikiTOC(), | ||
new MediaWikiText("test", { bold: true }), | ||
new MediaWikiBreak(), | ||
new MediaWikiText("The Old School Team.", { italics: true }), | ||
]; | ||
const transformed = new NewsHeaderTransformer().transform(originalContent); | ||
expect( | ||
new MediaWikiBuilder().addContents(transformed).build() | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
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,35 @@ | ||
import { | ||
MediaWikiBreak, | ||
MediaWikiContent, | ||
MediaWikiTransformer, | ||
} from "../../../utils/mediawiki"; | ||
|
||
class NewsBreakTransformer extends MediaWikiTransformer { | ||
transform(content: MediaWikiContent[]): MediaWikiContent[] { | ||
const transformedContent = []; | ||
for (let index = 0; index < content.length; index++) { | ||
const current = content[index]; | ||
if ( | ||
index > 0 && | ||
index < content.length - 1 && | ||
current instanceof MediaWikiBreak | ||
) { | ||
const before = content[index - 1]; | ||
const after = content[index + 1]; | ||
if ( | ||
before instanceof MediaWikiBreak && | ||
after instanceof MediaWikiBreak | ||
) { | ||
index++; | ||
} else { | ||
transformedContent.push(current); | ||
} | ||
} else { | ||
transformedContent.push(current); | ||
} | ||
} | ||
return transformedContent; | ||
} | ||
} | ||
|
||
export default NewsBreakTransformer; |
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,39 @@ | ||
import { | ||
MediaWikiBreak, | ||
MediaWikiContent, | ||
MediaWikiHeader, | ||
MediaWikiText, | ||
MediaWikiTransformer, | ||
} from "../../../utils/mediawiki"; | ||
|
||
class NewsHeaderTransformer extends MediaWikiTransformer { | ||
transform(content: MediaWikiContent[]): MediaWikiContent[] { | ||
const transformedContent = []; | ||
for (let index = 0; index < content.length; index++) { | ||
const current = content[index]; | ||
if ( | ||
index > 0 && | ||
index < content.length - 1 && | ||
current instanceof MediaWikiText && | ||
current.value.length <= 70 && | ||
current.styling?.bold | ||
) { | ||
const before = content[index - 1]; | ||
const after = content[index + 1]; | ||
if ( | ||
before instanceof MediaWikiBreak && | ||
after instanceof MediaWikiBreak | ||
) { | ||
transformedContent.push(new MediaWikiHeader(current.value, 3)); | ||
} else { | ||
transformedContent.push(current); | ||
} | ||
} else { | ||
transformedContent.push(current); | ||
} | ||
} | ||
return transformedContent; | ||
} | ||
} | ||
|
||
export default NewsHeaderTransformer; |
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as NewsBreakTransformer } from "./breakTransformer"; | ||
export { default as NewsFooterTransformer } from "./footerTransformer"; | ||
export { default as NewsHeaderTransformer } from "./headerTransformer"; | ||
export { default as NewsImageCaptionTransformer } from "./imageCaptionTransformer"; |
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