Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | 3x 42x 11x 31x 10x 10x 4x 9x 9x 65x 4x 4x 4x 4x 4x 4x 28x 28x 28x 28x 28x 28x 4x 3x 3x 3x 3x 3x 6x 6x 6x 6x 6x 3x 32x 315x 315x 275x 14x 14x 14x 14x 14x 145x 145x 14x 14x 23x 23x 234x 23x 23x 147x 147x 147x 147x 78x 78x 78x 78x 147x 147x 20x 20x 20x 20x 11x 11x 11x 11x 11x 20x 20x 20x 144x 144x 20x 13x 5x | /**
* Template generator module
* Generates markdown templates for CV/rirekisho
*/
import type { OutputFormat } from '../types/config.js';
import type {
FrontmatterFieldTemplate,
SectionInfo,
SectionTemplate,
TemplateDefinition,
TemplateInfo,
TemplateLanguage,
TemplateOptions,
} from '../types/template.js';
import { EN_TEMPLATE } from './definitions/en.js';
import { JA_TEMPLATE } from './definitions/ja.js';
/**
* Language display names
*/
const LANGUAGE_NAMES: Record<TemplateLanguage, string> = {
en: 'English',
ja: '日本語 (Japanese)',
};
/**
* Get template definition for a language
*/
export function getTemplateDefinition(
language: TemplateLanguage,
): TemplateDefinition {
switch (language) {
case 'ja':
return JA_TEMPLATE;
case 'en':
default:
return EN_TEMPLATE;
}
}
/**
* Get information about available templates
*/
export function getTemplateInfo(language: TemplateLanguage): TemplateInfo {
const definition = getTemplateDefinition(language);
return {
language,
languageName: LANGUAGE_NAMES[language],
formats: ['cv', 'rirekisho', 'both', 'cover_letter'],
sectionCount: definition.sections.length,
frontmatterFieldCount: definition.frontmatterFields.length,
};
}
/**
* Get all available template infos
*/
export function getAllTemplateInfos(): TemplateInfo[] {
return getAvailableLanguages().map(getTemplateInfo);
}
/**
* Get section info for a specific language and format
*/
export function getSectionInfos(
language: TemplateLanguage,
format: OutputFormat,
): SectionInfo[] {
const definition = getTemplateDefinition(language);
const sections = filterSectionsForFormat(definition.sections, format);
return sections.map((section) => ({
id: section.id,
title: section.title,
description: section.description,
usage: section.usage,
}));
}
/**
* Format section list for display
*/
export function formatSectionList(
language: TemplateLanguage,
format: OutputFormat,
): string {
const sections = getSectionInfos(language, format);
const lines: string[] = [];
const header =
language === 'ja'
? `利用可能なセクション (${format} フォーマット):`
: `Available sections (${format} format):`;
lines.push(header);
lines.push('');
for (const section of sections) {
const usageLabel =
section.usage === 'both'
? language === 'ja'
? '共通'
: 'both'
: section.usage;
lines.push(` ${section.id}`);
lines.push(
` ${language === 'ja' ? 'タイトル' : 'Title'}: ${section.title}`,
);
lines.push(` ${language === 'ja' ? '用途' : 'Usage'}: ${usageLabel}`);
lines.push(
` ${language === 'ja' ? '説明' : 'Description'}: ${section.description}`,
);
lines.push('');
}
return lines.join('\n');
}
/**
* Format template list for display
*/
export function formatTemplateList(): string {
const infos = getAllTemplateInfos();
const lines: string[] = [];
lines.push('Available templates:');
lines.push('');
for (const info of infos) {
lines.push(` ${info.language} - ${info.languageName}`);
lines.push(` Formats: ${info.formats.join(', ')}`);
lines.push(` Sections: ${info.sectionCount}`);
lines.push(` Frontmatter fields: ${info.frontmatterFieldCount}`);
lines.push('');
}
return lines.join('\n');
}
/**
* Filter sections based on output format
*/
export function filterSectionsForFormat(
sections: readonly SectionTemplate[],
format: OutputFormat,
): SectionTemplate[] {
return sections.filter((section) => {
Iif (section.usage === 'all') return true;
if (format === 'both') return section.usage !== 'cover_letter';
return section.usage === 'both' || section.usage === format;
});
}
/**
* Generate frontmatter field descriptions as HTML comment block
* This is placed before the frontmatter to avoid YAML parsing issues
*/
export function generateFrontmatterDescription(
fields: readonly FrontmatterFieldTemplate[],
language: TemplateLanguage,
): string {
const requiredLabel = language === 'ja' ? '必須' : 'required';
const optionalLabel = language === 'ja' ? '任意' : 'optional';
const headerLabel =
language === 'ja'
? 'フロントマターフィールドの説明'
: 'Frontmatter Field Descriptions';
const lines: string[] = [`<!-- ${headerLabel}:`];
for (const field of fields) {
const reqLabel = field.required ? requiredLabel : optionalLabel;
lines.push(` ${field.key}: ${field.description} (${reqLabel})`);
}
lines.push('-->');
return lines.join('\n');
}
/**
* Generate frontmatter block
* Note: Comments are NOT included inside YAML frontmatter to avoid parsing issues
*/
export function generateFrontmatter(
fields: readonly FrontmatterFieldTemplate[],
_includeComments: boolean,
_language: TemplateLanguage,
): string {
const lines: string[] = ['---'];
for (const field of fields) {
lines.push(`${field.key}: ${field.example}`);
}
lines.push('---');
return lines.join('\n');
}
/**
* Generate section block
*/
export function generateSection(
section: SectionTemplate,
includeComments: boolean,
_language: TemplateLanguage,
): string {
const lines: string[] = [];
lines.push(`# ${section.title}`);
lines.push('');
if (includeComments) {
const commentLines = section.description.split('\n');
for (const line of commentLines) {
lines.push(`<!-- ${line} -->`);
}
lines.push('');
}
lines.push(section.content);
return lines.join('\n');
}
/**
* Generate complete markdown template
*/
export function generateTemplate(options: TemplateOptions): string {
const definition = getTemplateDefinition(options.language);
const sections = filterSectionsForFormat(definition.sections, options.format);
const parts: string[] = [];
// Add header comment
if (options.includeComments) {
const headerComment =
options.language === 'ja'
? `<!--
md2cv テンプレート
フォーマット: ${options.format}
このテンプレートを編集して、あなたの CV/履歴書を作成してください。
コメント(<!-- -->)は出力には含まれません。
使い方:
md2cv -i this-file.md -f ${options.format}
詳細: https://github.com/yuyash/md2cv
-->`
: `<!--
md2cv Template
Format: ${options.format}
Edit this template to create your CV/resume.
Comments (<!-- -->) will not appear in the output.
Usage:
md2cv -i this-file.md -f ${options.format}
Documentation: https://github.com/yuyash/md2cv
-->`;
parts.push(headerComment);
parts.push('');
// Add frontmatter field descriptions as HTML comment (outside YAML block)
parts.push(
generateFrontmatterDescription(
definition.frontmatterFields,
options.language,
),
);
parts.push('');
}
// Add frontmatter
parts.push(
generateFrontmatter(
definition.frontmatterFields,
options.includeComments,
options.language,
),
);
parts.push('');
// Add sections
for (const section of sections) {
parts.push(
generateSection(section, options.includeComments, options.language),
);
parts.push('');
}
return parts.join('\n').trimEnd() + '\n';
}
/**
* Get available template languages
*/
export function getAvailableLanguages(): TemplateLanguage[] {
return ['en', 'ja'];
}
/**
* Validate template language
*/
export function isValidLanguage(lang: string): lang is TemplateLanguage {
return getAvailableLanguages().includes(lang as TemplateLanguage);
}
|