kopia lustrzana https://github.com/shoelace-style/shoelace
add metadata to search index
rodzic
ba3117f435
commit
ac6ae43449
|
@ -6,7 +6,7 @@ Components with the <sl-badge type="warning" pill>Experimental</sl-badge> badge
|
||||||
|
|
||||||
_During the beta period, these restrictions may be relaxed in the event of a mission-critical bug._ 🐛
|
_During the beta period, these restrictions may be relaxed in the event of a mission-critical bug._ 🐛
|
||||||
|
|
||||||
## Next
|
## 2.0.0-beta.51
|
||||||
|
|
||||||
A number of users had trouble counting characters that repeat, so this release improves design token pattern so "t-shirt sizes" are more accessible. For example, `--sl-font-size-xxx-large` has become `--sl-font-size-3x-large`. This change applies to all design tokens that use this scale.
|
A number of users had trouble counting characters that repeat, so this release improves design token pattern so "t-shirt sizes" are more accessible. For example, `--sl-font-size-xxx-large` has become `--sl-font-size-3x-large`. This change applies to all design tokens that use this scale.
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import glob from 'globby';
|
import glob from 'globby';
|
||||||
import lunr from 'lunr';
|
import lunr from 'lunr';
|
||||||
|
import { getAllComponents } from './shared.js';
|
||||||
|
|
||||||
|
const metadata = JSON.parse(fs.readFileSync('./dist/custom-elements.json', 'utf8'));
|
||||||
|
|
||||||
console.log('Generating search index for documentation');
|
console.log('Generating search index for documentation');
|
||||||
|
|
||||||
|
@ -24,6 +27,36 @@ console.log('Generating search index for documentation');
|
||||||
return headings;
|
return headings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMembers(markdown) {
|
||||||
|
const members = [];
|
||||||
|
const headers = markdown.match(/\[component-header:([a-z-]+)\]/g);
|
||||||
|
|
||||||
|
if (!headers) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
headers.map(header => {
|
||||||
|
const tagName = header.match(/\[component-header:([a-z-]+)\]/)[1];
|
||||||
|
const component = getAllComponents(metadata).find(component => component.tagName === tagName);
|
||||||
|
|
||||||
|
if (component) {
|
||||||
|
const fields = ['members', 'cssProperties', 'cssParts', 'slots', 'events'];
|
||||||
|
|
||||||
|
fields.map(field => {
|
||||||
|
if (component[field]) {
|
||||||
|
component[field].map(entry => {
|
||||||
|
if (entry.name) members.push(entry.name);
|
||||||
|
if (entry.description) members.push(entry.description);
|
||||||
|
if (entry.attribute) members.push(entry.attribute);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return members.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
const files = await glob('./docs/**/*.md');
|
const files = await glob('./docs/**/*.md');
|
||||||
const map = {};
|
const map = {};
|
||||||
const searchIndex = lunr(function () {
|
const searchIndex = lunr(function () {
|
||||||
|
@ -32,6 +65,7 @@ console.log('Generating search index for documentation');
|
||||||
this.ref('id'); // id
|
this.ref('id'); // id
|
||||||
this.field('t', { boost: 10 }); // title
|
this.field('t', { boost: 10 }); // title
|
||||||
this.field('h', { boost: 5 }); // headings
|
this.field('h', { boost: 5 }); // headings
|
||||||
|
this.field('m', { boost: 5 }); // members (props, methods, events, etc.)
|
||||||
this.field('c'); // content
|
this.field('c'); // content
|
||||||
|
|
||||||
files.map((file, index) => {
|
files.map((file, index) => {
|
||||||
|
@ -53,8 +87,9 @@ console.log('Generating search index for documentation');
|
||||||
.filter(heading => heading.level > 1)
|
.filter(heading => heading.level > 1)
|
||||||
.map(heading => heading.content)
|
.map(heading => heading.content)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
const members = getMembers(content);
|
||||||
|
|
||||||
this.add({ id: index, t: title, h: headings, c: content });
|
this.add({ id: index, t: title, h: headings, m: members, c: content });
|
||||||
|
|
||||||
map[index] = { title, url };
|
map[index] = { title, url };
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,30 +5,13 @@
|
||||||
//
|
//
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { getAllComponents } from './shared.js';
|
||||||
|
|
||||||
const metadata = JSON.parse(fs.readFileSync('./dist/custom-elements.json', 'utf8'));
|
const metadata = JSON.parse(fs.readFileSync('./dist/custom-elements.json', 'utf8'));
|
||||||
|
|
||||||
function getAllComponents() {
|
|
||||||
const allComponents = [];
|
|
||||||
|
|
||||||
metadata.modules.map(module => {
|
|
||||||
module.declarations?.map(declaration => {
|
|
||||||
if (declaration.customElement) {
|
|
||||||
const component = declaration;
|
|
||||||
|
|
||||||
if (component) {
|
|
||||||
allComponents.push(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return allComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Generating custom data for VS Code');
|
console.log('Generating custom data for VS Code');
|
||||||
|
|
||||||
const components = getAllComponents();
|
const components = getAllComponents(metadata);
|
||||||
const vscode = { tags: [] };
|
const vscode = { tags: [] };
|
||||||
|
|
||||||
components.map(component => {
|
components.map(component => {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
export function getAllComponents(metadata) {
|
||||||
|
const allComponents = [];
|
||||||
|
|
||||||
|
metadata.modules.map(module => {
|
||||||
|
module.declarations?.map(declaration => {
|
||||||
|
if (declaration.customElement) {
|
||||||
|
const component = declaration;
|
||||||
|
|
||||||
|
if (component) {
|
||||||
|
allComponents.push(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return allComponents;
|
||||||
|
}
|
Ładowanie…
Reference in New Issue