fix: 智能识别配方名称 + 新增默认保存到个人配方
- 修复空格/无分隔符时配方名称无法识别的问题 - 支持"长高芳香调理8永久花10"连写格式自动分离名称 - 所有用户新增配方默认保存到个人配方(diary),不进公共库 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -266,7 +266,41 @@ export function parseSingleBlock(raw, oilNames) {
|
||||
* appears after some oils have been found, it starts a new recipe.
|
||||
*/
|
||||
export function parseMultiRecipes(raw, oilNames) {
|
||||
const parts = raw.split(/[,,、\n\r]+/).map(s => s.trim()).filter(s => s)
|
||||
// First split by lines/commas, then within each part also try space splitting
|
||||
const roughParts = raw.split(/[,,、\n\r]+/).map(s => s.trim()).filter(s => s)
|
||||
const parts = []
|
||||
for (const rp of roughParts) {
|
||||
// If the part has spaces and contains mixed name+oil, split by spaces too
|
||||
// But only if spaces actually separate meaningful chunks
|
||||
const spaceParts = rp.split(/\s+/).filter(s => s)
|
||||
if (spaceParts.length > 1) {
|
||||
parts.push(...spaceParts)
|
||||
} else {
|
||||
// No spaces or single chunk — try to separate name prefix from oil+number
|
||||
// e.g. "长高芳香调理8" → check if any oil is inside
|
||||
const hasOilInside = oilNames.some(oil => rp.includes(oil))
|
||||
if (hasOilInside && rp.length > 2) {
|
||||
// Find the earliest oil match position
|
||||
let earliest = rp.length
|
||||
let earliestOil = ''
|
||||
for (const oil of oilNames) {
|
||||
const pos = rp.indexOf(oil)
|
||||
if (pos >= 0 && pos < earliest) {
|
||||
earliest = pos
|
||||
earliestOil = oil
|
||||
}
|
||||
}
|
||||
if (earliest > 0) {
|
||||
parts.push(rp.substring(0, earliest))
|
||||
parts.push(rp.substring(earliest))
|
||||
} else {
|
||||
parts.push(rp)
|
||||
}
|
||||
} else {
|
||||
parts.push(rp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const recipes = []
|
||||
let current = { nameParts: [], ingredientParts: [], foundOil: false }
|
||||
|
||||
Reference in New Issue
Block a user