Skip to content

Commit

Permalink
Merge pull request #145 from ionic-team/find-article-with-markdown
Browse files Browse the repository at this point in the history
Fix: Index html file when multiple article elements present in file
  • Loading branch information
praveenn77 committed May 8, 2024
2 parents 1afb5ab + e5f031f commit 46bccbd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.npmrc
node_modules
node_modules
.DS_Store
17 changes: 14 additions & 3 deletions src/html-to-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ const toText = require('hast-util-to-text')
const is = require('unist-util-is')
const toVfile = require('to-vfile')

function findArticleWithMarkdown(articles) {
for (let i = 0; i < articles.length; i++) {
markdown = select('.markdown', articles[i])
if (markdown) {
return [markdown, articles[i]];
}
}
return [null, null];
}

// Build search data for a html
function* scanDocuments({ path, url }) {
let vfile
Expand All @@ -24,11 +34,12 @@ function* scanDocuments({ path, url }) {

const hast = unified().use(parse, { emitParseErrors: false }).parse(vfile)

const article = select('article', hast)
if (!article) {
const articles = selectAll('article', hast)
if (!articles) {
return
}
const markdown = select('.markdown', article)

const [markdown, article] = findArticleWithMarkdown(articles)
if (!markdown) {
return
}
Expand Down

0 comments on commit 46bccbd

Please sign in to comment.