Skip to content

Commit bb9a644

Browse files
committed
ページの別名で検索できるよう別名メタ情報を追加
cpprefjp/site#1545
1 parent 0c7e4e2 commit bb9a644

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

crsearch.json/run.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class Validator(object):
8787
'type': 'string',
8888
},
8989
},
90+
'aliases': {
91+
'type': 'array',
92+
'items': {
93+
'type': 'string',
94+
},
95+
},
9096
},
9197
},
9298
},
@@ -409,6 +415,18 @@ def make_index(self, md, names, idgen, nojump):
409415

410416
index['attributes'] = attributes
411417

418+
# alias メタ情報を処理(カンマ区切りで複数のエイリアスを指定可能)
419+
if 'alias' in metas:
420+
aliases = []
421+
for alias_entry in metas['alias']:
422+
# カンマ区切りで複数のエイリアスを分割
423+
for alias in alias_entry.split(','):
424+
alias = alias.strip()
425+
if alias:
426+
aliases.append(alias)
427+
if aliases:
428+
index['aliases'] = aliases
429+
412430
return index, metas
413431

414432
def generate(self, base_dir, file_paths, all_file_paths):

crsearch.json/test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def test_get_meta(self):
1616
result = run.Generator().get_meta(md)
1717
self.assertEqual({'text': ['foo', 'piyo'], 'text2': ['bar']}, result)
1818

19+
def test_get_meta_alias(self):
20+
md = '''\
21+
* text1,text2,text3[meta alias]
22+
'''
23+
result = run.Generator().get_meta(md)
24+
self.assertEqual({'alias': ['text1,text2,text3']}, result)
25+
1926
def test_validate(self):
2027
value = {
2128
'base_url': 'https://cpprefjp.github.io',
@@ -40,6 +47,30 @@ def test_validate(self):
4047
}
4148
run.Validator().validate(value)
4249

50+
def test_validate_with_aliases(self):
51+
value = {
52+
'base_url': 'https://cpprefjp.github.io',
53+
'database_name': 'cpprefjp',
54+
'ids': [{
55+
'type': 'header',
56+
'key': ['vector'],
57+
}],
58+
'namespaces': [
59+
{
60+
'namespace': ['reference'],
61+
'path_prefixes': ['reference'],
62+
'indexes': [
63+
{
64+
'id': 0,
65+
'page_id': ['vector'],
66+
'aliases': ['dynamic array', 'resizable array'],
67+
},
68+
],
69+
},
70+
],
71+
}
72+
run.Validator().validate(value)
73+
4374
def test_generate(self):
4475
paths = [
4576
'test/reference/array.md',

0 commit comments

Comments
 (0)