Scrapboxの検索窓をHelpfeel的に使う
(2022/10/27)
ScrapboxだけでHelpfeel的検索ができるような工夫をしている
Helpfeel記述のあるページにおいて、Helpfeel記述を展開したタイトルのページを作って同じ内容を貼っている
タイトルの先頭に「_」をつけることで、自動生成したものであることを示している
そういうページはリストには表示されないようにしている (settingsで設定)
code:style.css
.grid-style-itemdata-page-title^="_"
{display: none !important;}
以下のような手順
1. /masuiのデータをmasui.jsonにエクスポートしておく
2. % wget -q -O - "https://scrapbox.io/api/code/masui/Scrapboxの検索窓をHelpfeel的に使う/expand.rb | ruby - masui > new.json
3. new.jsonをインポート
こうしておくと、「Appple」みたいな間違ったキーワードでもQuickSearchが有効に働く
https://gyazo.com/443c8fda7f8a8e1bff10026009e3ac77
https://gyazo.com/a8d62f2c40f92f5ab40188e832ba5f47
以下のようなsbexpandコマンドを作るとラク
code:sbexpand
#!/bin/sh
#
# masui.json のあるところで以下を実行
# % sbexpand masui
#
wget -q -O - "https://scrapbox.io/api/code/masui/Scrapboxの検索窓をHelpfeel的に使う/expand.rb" | ruby - $*
この場合の手順は以下のとおり
1. プロジェクトのデータをプロジェクト名.jsonにエクスポート
2. sbexpand プロジェクト名 > new.json
3. new.jsonをインポート (全部上書き)
code:expand.rb
require 'json'
require 're_expand'
project = ARGV0 || "toshiyukimasui"
project = project.sub(/\.json$/,'')
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 glossarykw
s.sub!("{#{kw}}",glossarykw)
end
end
helps << s
else
normallines << line
end
}
normallines.shift # タイトル行を削除
if helps.length > 0
helps.each { |help|
help.gsub(/\/,'').gsub(/\/,'').expand { |s|
name = s0
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
? Tips: Helpfeel記法を展開してQuickSearchで検索できるようにする