Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/publish-skills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ jobs:
--latest=false
fi
gh release upload skills-latest dist/skill-archives/*.zip --clobber

# Remove unprefixed archives only after the renamed archives are published.
gh release view skills-latest --json assets --jq '.assets[].name' > "$RUNNER_TEMP/interview-skill-assets.txt"
while IFS= read -r slug; do
if grep -Fxq "$slug.zip" "$RUNNER_TEMP/interview-skill-assets.txt"; then
gh release delete-asset skills-latest "$slug.zip" --yes
fi
done < <(node --input-type=module -e "import {readFileSync} from 'node:fs'; for (const {slug} of JSON.parse(readFileSync('skills/catalog.json'))) console.log(slug)")
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@ npx skills@latest add https://github.com/Angular-RU/angular-ru-interview-questio
Или только Angular:

```bash
npx skills@latest add https://github.com/Angular-RU/angular-ru-interview-questions/releases/download/skills-latest/angular.zip
npx skills@latest add https://github.com/Angular-RU/angular-ru-interview-questions/releases/download/skills-latest/angular-ru-interview-angular.zip
```

Генератор использует `src/pages/**/index.md` как единственный источник вопросов и ответов. При сборке он создает
`skills/<тема>/SKILL.md` и `references/part-XX.md` локально; эти файлы **не хранятся в Git**. После каждого push в
`main` GitHub Actions публикует обновленные ZIP-архивы в
Все имена скиллов начинаются с `angular-ru-interview-`, чтобы не конфликтовать с другими источниками.

Ранее установленные скиллы с короткими именами (`angular`, `react` и т. д.) нужно удалить и установить заново.

Переименование установленных скиллов не происходит автоматически. URL страниц справочника остаются прежними.

Генератор использует `src/pages/**/index.md` как единственный источник вопросов и ответов.

При сборке он создает `SKILL.md` и `references/part-XX.md` в папке `skills/angular-ru-interview-<тема>/`.

Сгенерированные файлы **не хранятся в Git**.

После каждого push в `main` GitHub Actions публикует ZIP-архивы в
[GitHub Release `skills-latest`](https://github.com/Angular-RU/angular-ru-interview-questions/releases/tag/skills-latest).
Каждую тему можно установить отдельно, а `all.zip` содержит все 26 тем. После установки все вопросы и ответы доступны
без доступа к сайту. Генерация и проверка выполняются автоматически через `npm run skills:check`.

Каждую тему можно установить отдельно, а `all.zip` содержит все 26 тем.

После установки вопросы и ответы доступны без доступа к сайту. Генерация и проверка выполняются автоматически через
`npm run skills:check`.

## Основы и инструменты

Expand Down
13 changes: 10 additions & 3 deletions scripts/check-skills.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ import {join} from 'node:path';

const root = new URL('../', import.meta.url).pathname;
const catalog = JSON.parse(readFileSync(join(root, 'skills/catalog.json'), 'utf8'));
const {prefix} = JSON.parse(readFileSync(join(root, 'skills/naming.json'), 'utf8'));
assert.match(prefix, /^[a-z0-9]+(?:-[a-z0-9]+)*-$/);
const slugs = new Set();
const names = new Set();

for (const skill of catalog) {
assert.match(skill.slug, /^[a-z0-9]+(?:-[a-z0-9]+)*$/);
assert(!slugs.has(skill.slug), `Duplicate skill: ${skill.slug}`);
slugs.add(skill.slug);
const name = `${prefix}${skill.slug}`;
assert(name.length <= 64, `Skill name exceeds 64 characters: ${name}`);
assert(!names.has(name), `Duplicate skill name: ${name}`);
names.add(name);
assert(skill.title && skill.description && skill.category);
assert(skill.topics.length >= 3, `Missing topic coverage: ${skill.slug}`);

const pagePath = join(root, 'src/pages', skill.slug, 'index.md');
assert(existsSync(pagePath), `Missing topic page: ${skill.slug}`);
assert.match(readFileSync(pagePath, 'utf8'), /kind:\s*questions/);

const path = join(root, 'skills', skill.slug, 'SKILL.md');
const path = join(root, 'skills', name, 'SKILL.md');
assert(existsSync(path), `Missing SKILL.md: ${skill.slug}`);
const content = readFileSync(path, 'utf8');
assert(content.startsWith(`---\nname: ${skill.slug}\ndescription:`), `Invalid frontmatter: ${skill.slug}`);
assert(content.startsWith(`---\nname: ${name}\ndescription:`), `Invalid frontmatter: ${skill.slug}`);
assert(content.includes(`/interview/${skill.slug}/`), `Missing handbook link: ${skill.slug}`);
}

Expand All @@ -33,6 +40,6 @@ assert.deepEqual([...slugs].sort(), pageSlugs, 'Catalog must match all question
const skillDirs = readdirSync(join(root, 'skills'))
.filter((entry) => statSync(join(root, 'skills', entry)).isDirectory())
.sort();
assert.deepEqual(skillDirs, [...slugs].sort(), 'Skill directories must match catalog');
assert.deepEqual(skillDirs, [...names].sort(), 'Skill directories must match catalog');

console.log(`Validated ${catalog.length} installable skills and question pages.`);
34 changes: 28 additions & 6 deletions scripts/generate-skills.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import assert from 'node:assert/strict';
import {existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync} from 'node:fs';
import {existsSync, mkdirSync, readFileSync, readdirSync, rmSync, unlinkSync, writeFileSync} from 'node:fs';
import {join} from 'node:path';
import {fileURLToPath} from 'node:url';

const root = fileURLToPath(new URL('../', import.meta.url));
const catalog = JSON.parse(readFileSync(join(root, 'skills/catalog.json'), 'utf8'));
const {prefix} = JSON.parse(readFileSync(join(root, 'skills/naming.json'), 'utf8'));
assert.match(prefix, /^[a-z0-9]+(?:-[a-z0-9]+)*-$/);
const skillName = (slug) => `${prefix}${slug}`;
const check = process.argv.includes('--check');
const maxChunkSize = 48_000;
const generated = new Set();
Expand Down Expand Up @@ -74,14 +77,16 @@ function splitIntoChunks(markdown) {
}

function generateSkill(skill) {
const name = skillName(skill.slug);
assert(name.length <= 64, `Skill name exceeds 64 characters: ${name}`);
const page = readFileSync(join(root, 'src/pages', skill.slug, 'index.md'), 'utf8');
const {markdown, count} = convertQuestions(page, skill.slug);
const chunks = splitIntoChunks(markdown);
const items = new Map();
const index = [];
for (const [i, chunk] of chunks.entries()) {
const filename = 'part-' + String(i + 1).padStart(2, '0') + '.md';
const file = 'skills/' + skill.slug + '/references/' + filename;
const file = 'skills/' + name + '/references/' + filename;
const questions = (chunk.text.match(/^#### Вопрос: /gm) ?? []).length;
const topics = chunk.topics.join(', ');
items.set(
Expand All @@ -103,10 +108,10 @@ function generateSkill(skill) {
);

items.set(
'skills/' + skill.slug + '/SKILL.md',
'skills/' + name + '/SKILL.md',
[
'---',
'name: ' + skill.slug,
'name: ' + name,
'description: ' +
JSON.stringify(
'Вопросы и ответы для технического собеседования по теме ' +
Expand Down Expand Up @@ -141,6 +146,23 @@ function generateSkill(skill) {
return items;
}

// Skill names used to match page slugs. Remove only directories produced by the old generator.
for (const {slug} of catalog) {
const legacyDirectory = join(root, 'skills', slug);
if (!existsSync(legacyDirectory)) continue;

const legacySkillFile = join(legacyDirectory, 'SKILL.md');
assert(existsSync(legacySkillFile), `Unexpected legacy directory: skills/${slug}`);
const content = readFileSync(legacySkillFile, 'utf8');
assert(
content.startsWith(`---\nname: ${slug}\ndescription:`) &&
content.includes('Angular-RU/angular-ru-interview-questions'),
`Refusing to remove an unknown skill directory: skills/${slug}`,
);
if (check) throw new Error(`Stale unprefixed skill directory: skills/${slug}`);
rmSync(legacyDirectory, {recursive: true, force: true});
}

for (const skill of catalog) {
const items = generateSkill(skill);
for (const [relative, content] of items) {
Expand All @@ -155,10 +177,10 @@ for (const skill of catalog) {
}
}

const references = join(root, 'skills', skill.slug, 'references');
const references = join(root, 'skills', skillName(skill.slug), 'references');
if (existsSync(references)) {
for (const filename of readdirSync(references)) {
const relative = 'skills/' + skill.slug + '/references/' + filename;
const relative = 'skills/' + skillName(skill.slug) + '/references/' + filename;
if (!generated.has(relative) && filename.startsWith('part-') && filename.endsWith('.md')) {
if (check) throw new Error('Stale generated file: ' + relative);
unlinkSync(join(references, filename));
Expand Down
3 changes: 3 additions & 0 deletions skills/naming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prefix": "angular-ru-interview-"
}
8 changes: 4 additions & 4 deletions src/components/SkillHero.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import type {Skill} from '../data/skills';
import {installCommand} from '../data/skills';
import {installCommand, skillName} from '../data/skills';
import SkillInstall from './SkillInstall.astro';

interface Props {
Expand All @@ -16,7 +16,7 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, '');
aria-labelledby="skill-hero-title"
>
<div class="skill-hero__content">
<p class="skill-hero__eyebrow">/{skill.slug} <span>· AI Skill</span></p>
<p class="skill-hero__eyebrow">/{skillName(skill.slug)} <span>· AI Skill</span></p>
<h1 id="skill-hero-title">{skill.title}</h1>
<p class="skill-hero__lead">{skill.description}</p>

Expand All @@ -26,7 +26,7 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, '');
<a href={`${base}/skills/`}>Все AI Skills</a>
<span aria-hidden="true">·</span>
<a
href={`https://github.com/Angular-RU/angular-ru-interview-questions/releases/download/skills-latest/${skill.slug}.zip`}
href={`https://github.com/Angular-RU/angular-ru-interview-questions/releases/download/skills-latest/${skillName(skill.slug)}.zip`}
rel="noopener noreferrer"
target="_blank"
>
Expand All @@ -48,7 +48,7 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, '');
</div>
<div class="skill-hero__terminal">
<div class="skill-hero__terminal-label">READY TO PRACTICE</div>
<div class="skill-hero__terminal-title">/{skill.slug}</div>
<div class="skill-hero__terminal-title">/{skillName(skill.slug)}</div>
<div class="skill-hero__terminal-line"><span>01</span> Choose your level</div>
<div class="skill-hero__terminal-line"><span>02</span> Answer questions</div>
<div class="skill-hero__terminal-line">
Expand Down
5 changes: 4 additions & 1 deletion src/data/skills.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import catalog from '../../skills/catalog.json';
import naming from '../../skills/naming.json';

export const skills = catalog;
export type Skill = (typeof skills)[number];

export const skillName = (slug: string): string => `${naming.prefix}${slug}`;

const releaseUrl =
'https://github.com/Angular-RU/angular-ru-interview-questions/releases/download/skills-latest';

export const installAllCommand = `npx skills@latest add ${releaseUrl}/all.zip`;

export const installCommand = (slug: string): string =>
`npx skills@latest add ${releaseUrl}/${slug}.zip`;
`npx skills@latest add ${releaseUrl}/${skillName(slug)}.zip`;
4 changes: 2 additions & 2 deletions src/pages/skills/index.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import Layout from '../../layouts/Layout.astro';
import SkillInstall from '../../components/SkillInstall.astro';
import {installAllCommand, skills} from '../../data/skills';
import {installAllCommand, skillName, skills} from '../../data/skills';

const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const groups = [...new Set(skills.map(({category}) => category))];
Expand Down Expand Up @@ -54,7 +54,7 @@ const groups = [...new Set(skills.map(({category}) => category))];
<span class="skills-catalog__card-title">{skill.title}</span>
<span class="skills-catalog__card-description">{skill.description}</span>
<span class="skills-catalog__card-footer">
<code>/{skill.slug}</code>
<code>/{skillName(skill.slug)}</code>
<span aria-hidden="true">↗</span>
</span>
</a>
Expand Down
Loading