All files / generator resume_ja.ts

100% Statements 17/17
91.66% Branches 11/12
100% Functions 6/6
100% Lines 16/16

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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346                                            21x 21x                     21x   21x 21x   21x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     21x                 21x         21x 21x     21x   21x     13x       13x                 21x       21x                                              
/**
 * Japanese CV Generator (職務経歴書スタイル)
 * Generates HTML for Japanese CV format with Mincho font
 */
 
import type { CVOptions, PageMargins, PaperSize } from '../types/config.js';
import type { ParsedSection } from '../types/sections.js';
import { isSectionValidForFormat } from '../types/sections.js';
import type { CVInput } from './common.js';
import {
  PAGE_SIZES,
  escapeHtml,
  jaLocale,
  renderSectionContent,
} from './common.js';
 
export type { CVInput };
 
/**
 * Get current date in Japanese format (yyyy年mm月dd日現在)
 */
function getCurrentDateJa(): string {
  const now = new Date();
  return `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日現在`;
}
 
/**
 * Generate base CSS styles for Japanese CV
 */
function generateStyles(
  paperSize: PaperSize,
  marginMm?: PageMargins,
  lineHeight?: number,
): string {
  const size = PAGE_SIZES[paperSize];
  // Default to 30mm margins if not specified
  const margins = marginMm ?? { top: 30, right: 30, bottom: 30, left: 30 };
  const lh = lineHeight ?? 1.6;
 
  return `
    :root {
      --cv-font-family: "Noto Serif JP", "Hiragino Mincho Pro", "Yu Mincho", "MS Mincho", serif;
      --cv-font-size-base: 10pt;
      --cv-font-size-title: 18pt;
      --cv-font-size-section: 12pt;
      --cv-font-size-small: 9pt;
      --cv-line-height: ${lh};
      --cv-color-text: #333;
      --cv-color-heading: #000;
      --cv-color-border: #333;
      --cv-color-background: #fff;
      --cv-spacing-section: 16px;
      --cv-spacing-entry: 12px;
    }
    @page {
      size: ${size.width}mm ${size.height}mm;
      margin: ${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm;
    }
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    html {
      background: #e0e0e0;
    }
    body {
      font-family: var(--cv-font-family);
      font-size: var(--cv-font-size-base);
      line-height: var(--cv-line-height);
      color: var(--cv-color-text);
      background: var(--cv-color-background);
      width: ${size.width}mm;
      min-height: ${size.height}mm;
      margin: 0 auto;
      padding: ${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm;
    }
    header {
      margin-bottom: 20px;
      padding-bottom: 15px;
    }
    .document-title {
      text-align: center;
      font-size: var(--cv-font-size-title);
      font-weight: bold;
      margin-bottom: 12px;
      color: var(--cv-color-heading);
    }
    .header-info {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }
    .header-name {
      font-size: var(--cv-font-size-base);
      color: var(--cv-color-heading);
    }
    .header-date {
      font-size: var(--cv-font-size-base);
      color: var(--cv-color-text);
    }
    section {
      margin-bottom: var(--cv-spacing-section);
    }
    h2 {
      font-size: var(--cv-font-size-section);
      font-weight: bold;
      border-bottom: 1px solid var(--cv-color-border);
      padding-bottom: 3px;
      margin-bottom: 10px;
      color: var(--cv-color-heading);
      page-break-after: avoid;
      break-after: avoid;
    }
    .entry {
      margin-bottom: var(--cv-spacing-entry);
      page-break-inside: avoid;
      break-inside: avoid;
    }
    .entry-header {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      flex-wrap: wrap;
    }
    .entry-title {
      font-weight: bold;
      color: var(--cv-color-heading);
    }
    .cert-item {
      font-size: var(--cv-font-size-small);
      color: var(--cv-color-heading);
      margin-bottom: 2px;
    }
    .lang-item {
      font-size: var(--cv-font-size-small);
    }
    .entry-subtitle {
      font-size: var(--cv-font-size-small);
      color: var(--cv-color-text);
    }
    .entry-date {
      color: var(--cv-color-text);
      font-size: var(--cv-font-size-small);
    }
    .entry-summary {
      margin-top: 4px;
      font-size: var(--cv-font-size-small);
    }
    ul {
      margin-left: 18px;
      margin-top: 4px;
    }
    li {
      margin-bottom: 2px;
      font-size: var(--cv-font-size-small);
    }
    p {
      margin-bottom: 8px;
      font-size: var(--cv-font-size-small);
    }
    .skills-grid {
      display: grid;
      gap: 2px 20px;
    }
    .skills-grid--cols-3 {
      grid-template-columns: 1fr 1fr 1fr;
    }
    .skill-item {
      font-size: var(--cv-font-size-small);
    }
    .skill-category {
      margin-bottom: 4px;
      font-size: var(--cv-font-size-small);
    }
    .skill-category-name {
      font-weight: bold;
    }
    .competency-entry {
      margin-bottom: 4px;
      font-size: var(--cv-font-size-small);
    }
    .competency-header {
      font-weight: bold;
    }
    .role {
      margin-bottom: 8px;
    }
    .role-header {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
    }
    .role-title {
      font-weight: 500;
      color: var(--cv-color-heading);
      font-size: var(--cv-font-size-small);
    }
    .role-team {
      font-weight: normal;
      color: var(--cv-color-text);
    }
    .entry-location {
      color: var(--cv-color-text);
      font-size: var(--cv-font-size-small);
    }
    .project {
      margin-left: 15px;
      margin-top: 4px;
    }
    .project-name {
      font-weight: 500;
      font-size: var(--cv-font-size-small);
    }
    /* Markdown inline styles */
    strong, b {
      font-weight: bold;
    }
    em, i {
      font-style: italic;
    }
    a {
      color: var(--cv-color-text);
      text-decoration: underline;
    }
    a:hover {
      color: var(--cv-color-heading);
    }
    code {
      font-family: "SF Mono", "Monaco", "Consolas", monospace;
      font-size: 0.9em;
      background: #f5f5f5;
      padding: 1px 4px;
      border-radius: 3px;
    }
    pre {
      font-family: "SF Mono", "Monaco", "Consolas", monospace;
      font-size: var(--cv-font-size-xs);
      background: #f5f5f5;
      padding: 8px;
      border-radius: 4px;
      overflow-x: auto;
      margin: 6px 0;
    }
    pre code {
      background: none;
      padding: 0;
    }
    blockquote {
      border-left: 3px solid var(--cv-color-border);
      padding-left: 12px;
      margin: 6px 0;
      color: var(--cv-color-muted);
      font-style: italic;
    }
    hr {
      border: none;
      border-top: 1px solid var(--cv-color-border);
      margin: 12px 0;
    }
    img {
      max-width: 100%;
      height: auto;
    }
    @media print {
      html {
        background: none;
      }
      body {
        width: auto;
        min-height: auto;
        padding: 0;
      }
    }
  `;
}
 
/**
 * Filter sections by format validity, preserving input order
 * Note: Section ordering is now handled by filterAndOrderSections in generator/index.ts
 */
function filterSections(sections: readonly ParsedSection[]): ParsedSection[] {
  return sections.filter((section) =>
    isSectionValidForFormat(section.id, 'cv'),
  );
}
 
/**
 * Generate Japanese HTML CV
 */
export function generateJaHtml(cv: CVInput, options: CVOptions): string {
  const styles = generateStyles(
    options.paperSize,
    options.marginMm,
    options.lineHeight,
  );
  const name = cv.metadata.name_ja ?? cv.metadata.name;
  const currentDate = getCurrentDateJa();
 
  // Filter sections (order is preserved from input)
  const filteredSections = filterSections(cv.sections);
 
  const sectionsHtml = filteredSections
    .map((section) => {
      // Add data-source-line attribute if sourceLines is available
      const sourceLineAttr = section.sourceLines
        ? ` data-source-line="${section.sourceLines.startLine}" data-source-end-line="${section.sourceLines.endLine}"`
        : '';
 
      return `
<section class="cv-section cv-section--${section.id}"${sourceLineAttr}>
  <h2>${escapeHtml(section.title)}</h2>
  ${renderSectionContent(section.content, section.id, jaLocale)}
</section>`;
    })
    .join('\n');
 
  // Include custom stylesheet if provided
  const customStylesHtml = options.customStylesheet
    ? `<style class="custom-styles">${options.customStylesheet}</style>`
    : '';
 
  return `<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>${escapeHtml(name)} - 職務経歴書</title>
  <style class="default-styles">${styles}</style>
  ${customStylesHtml}
</head>
<body class="cv cv--ja">
  <header class="cv-header"${cv.frontmatterSourceLines ? ` data-source-line="${cv.frontmatterSourceLines.startLine}" data-source-end-line="${cv.frontmatterSourceLines.endLine}"` : ''}>
    <div class="document-title">職務経歴書</div>
    <div class="header-info">
      <div class="header-name">${escapeHtml(name)}</div>
      <div class="header-date">${escapeHtml(currentDate)}</div>
    </div>
  </header>
  <main class="cv-content">
${sectionsHtml}
  </main>
</body>
</html>`;
}