зеркало из https://github.com/github/docs.git
Родитель
2c9ea3b661
Коммит
1ab125dd08
|
@ -9,7 +9,7 @@ const ignoredHeadingSlugs = ['in-this-article', 'further-reading', 'prerequisite
|
|||
|
||||
export default function parsePageSectionsIntoRecords(page) {
|
||||
const { href, $, languageCode } = page
|
||||
const title = $('h1').text().trim()
|
||||
const title = $('h1').first().text().trim()
|
||||
const breadcrumbsArray = $('[data-search=breadcrumbs] nav.breadcrumbs a')
|
||||
.map((i, el) => {
|
||||
return $(el).text().trim().replace('/', '').replace(/\s+/g, ' ')
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<div data-search="breadcrumbs">
|
||||
<nav class="breadcrumbs">
|
||||
<a href="#">GitHub Actions</a>
|
||||
<a href="#">actions learning path</a>
|
||||
<a href="#">I am the page title</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<h1>I am the page title</h1>
|
||||
|
||||
<div data-search="lead">
|
||||
<p>This is an introduction to the article.</p>
|
||||
</div>
|
||||
|
||||
<div data-search="article-body">
|
||||
<h1>A heading 1 inside the body</h1>
|
||||
<p>This won't be ignored.</p>
|
||||
</div>
|
|
@ -18,6 +18,10 @@ const fixtures = {
|
|||
path.join(__dirname, 'fixtures/page-without-body.html'),
|
||||
'utf8'
|
||||
),
|
||||
pageMultipleH1s: await fs.readFile(
|
||||
path.join(__dirname, 'fixtures/page-with-multiple-h1s.html'),
|
||||
'utf8'
|
||||
),
|
||||
}
|
||||
|
||||
describe('search parsePageSectionsIntoRecords module', () => {
|
||||
|
@ -78,4 +82,12 @@ describe('search parsePageSectionsIntoRecords module', () => {
|
|||
|
||||
expect(record).toEqual(expected)
|
||||
})
|
||||
|
||||
test('only picks up the first h1 for the title', () => {
|
||||
const html = fixtures.pageMultipleH1s
|
||||
const $ = cheerio.load(html)
|
||||
const href = '/example/href'
|
||||
const record = parsePageSectionsIntoRecords({ href, $, languageCode: 'en' })
|
||||
expect(record.title).toEqual('I am the page title')
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче