mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Title will now be extracted from front matter if title: is present.
This commit is contained in:
@@ -6,6 +6,11 @@ export function findNoteTitle (value) {
|
|||||||
if (splitted[0] === '---') {
|
if (splitted[0] === '---') {
|
||||||
let line = 0
|
let line = 0
|
||||||
while (++line < splitted.length) {
|
while (++line < splitted.length) {
|
||||||
|
if (splitted[line].startsWith('title:')) {
|
||||||
|
title = splitted[line].substring(6).trim()
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
if (splitted[line] === '---') {
|
if (splitted[line] === '---') {
|
||||||
splitted.splice(0, line + 1)
|
splitted.splice(0, line + 1)
|
||||||
|
|
||||||
@@ -14,17 +19,19 @@ export function findNoteTitle (value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
splitted.some((line, index) => {
|
if (title === null) {
|
||||||
const trimmedLine = line.trim()
|
splitted.some((line, index) => {
|
||||||
const trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim()
|
const trimmedLine = line.trim()
|
||||||
if (trimmedLine.match('```')) {
|
const trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim()
|
||||||
isInsideCodeBlock = !isInsideCodeBlock
|
if (trimmedLine.match('```')) {
|
||||||
}
|
isInsideCodeBlock = !isInsideCodeBlock
|
||||||
if (isInsideCodeBlock === false && (trimmedLine.match(/^# +/) || trimmedNextLine.match(/^=+$/))) {
|
}
|
||||||
title = trimmedLine
|
if (isInsideCodeBlock === false && (trimmedLine.match(/^# +/) || trimmedNextLine.match(/^=+$/))) {
|
||||||
return true
|
title = trimmedLine
|
||||||
}
|
return true
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (title === null) {
|
if (title === null) {
|
||||||
title = ''
|
title = ''
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ test('findNoteTitle#find should return a correct title (string)', t => {
|
|||||||
['====', '===='],
|
['====', '===='],
|
||||||
['```\n# hoge\n```', '```'],
|
['```\n# hoge\n```', '```'],
|
||||||
['hoge', 'hoge'],
|
['hoge', 'hoge'],
|
||||||
['---\nlayout: test\n---\n # hoge', '# hoge']
|
['---\nlayout: test\n---\n # hoge', '# hoge'],
|
||||||
|
['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', 'hoge hoge hoge'],
|
||||||
|
['---\ntitle:hoge\n---\n# fuga', 'hoge'],
|
||||||
|
['title: fuga\n# hoge', '# hoge']
|
||||||
]
|
]
|
||||||
|
|
||||||
testCases.forEach(testCase => {
|
testCases.forEach(testCase => {
|
||||||
@@ -23,4 +26,3 @@ test('findNoteTitle#find should return a correct title (string)', t => {
|
|||||||
t.is(findNoteTitle(input), expected, `Test for find() input: ${input} expected: ${expected}`)
|
t.is(findNoteTitle(input), expected, `Test for find() input: ${input} expected: ${expected}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user