Helpfeel記法を展開してQuickSearchで検索できるようにする.

Helpfeel記法を展開してQuickSearchで検索できるようにする.

(expanded from Scrapboxの検索窓をHelpfeel的に使う このページは編集しないでください)

(2022/10/27)

1. /xxxxxのデータを xxxxx.json にエクスポートしておく
2. % wget -q -O - "https://scrapbox.io/api/code/masui/Scrapboxの検索窓をHelpfeel的に使う/expand.rb | ruby - xxxxx > new.json
3. new.jsonをインポート

expand.rb
Copied!
require 'json'
require 're_expand'

project = ARGV[0] || "toshiyukimasui"

outdata = {}
pages = []
outdata['pages'] = pages

data = JSON.parse(File.read("#{project}.json"))

glossary = {}
data['pages'].each { |page|
if page['title'] == 'Glossary'
page['lines'].each { |line|
if line =~ /(.*):\s*(.*)$/
glossary[$1] = $2
end
}
end
}
data['pages'].each { |page|
title = page['title']
helps = []
normallines = []
expanded = false
page['lines'].each { |line|
if line =~ /expanded from/
expanded = true
end
if line =~ /^\s*\?\s+(.*)$/
s = $1
while s =~ /\{([a-zA-Z]+)\}/
kw = $1
if glossary[kw]
s.sub!("{#{kw}}",glossary[kw])
end
end
helps << s
else
normallines << line
end
}

normallines.shift # タイトル行を削除
if helps.length > 0
helps.each { |help|
help.gsub(/\[/,'').gsub(/\]/,'').expand { |s|
name = s[0]
if name != "" && name != title
entry = {}
entry['title'] = "#{name}."
entry['lines'] = [
"#{name}.",
"(expanded from [#{title}] [[このページは編集しないでください]])",
""
]
normallines.each { |normalline|
entry['lines'].push(normalline)
}
pages.push(entry)
end
}
}
# pages.push(page)
else
if !expanded
# pages.push(page)
end
end
}

puts outdata.to_json
Powered by Helpfeel