Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdf/emoji #233

Merged
merged 5 commits into from
Jan 5, 2024
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
4 changes: 3 additions & 1 deletion docker-compose.pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ services:
retries: 30

puppeteer:
image: ghcr.io/puppeteer/puppeteer:16.1.0
build:
context: pdf
dockerfile: Dockerfile
volumes:
- ./pdf:/home/pptruser/pdf
command: node pdf/export.js http://resume/ pdf/out/resume.pdf
Expand Down
25 changes: 16 additions & 9 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import ReactDOMServer from 'react-dom/server';
import { FaFileDownload, FaGithub } from 'react-icons/fa';

import dayjs from 'dayjs';
import { BsFillMusicPlayerFill } from 'react-icons/bs';
import { IconBaseProps } from 'react-icons';
Expand All @@ -18,12 +17,20 @@ const soundPlayerHtml = `
const iconStyle: IconBaseProps = {
style: { display: 'flex', alignItems: 'center', fontSize: '1.2rem' },
};
const githubIconHtml = ReactDOMServer.renderToString(FaGithub(iconStyle));
const fileDownloadIconHtml = ReactDOMServer.renderToString(
FaFileDownload(iconStyle),

const iconWrapper = (iconHtml: string, title: string) =>
`<span title="${title}">${iconHtml}</span><span class="capy--mobile-only" style="margin-left: 0.5rem">${title}</span>`;
const githubIconHtml = iconWrapper(
ReactDOMServer.renderToString(FaGithub(iconStyle)),
'リポジトリを表示する',
);
const fileDownloadIconHtml = iconWrapper(
ReactDOMServer.renderToString(FaFileDownload(iconStyle)),
'PDFファイルをダウンロードする',
);
const musicIconHtml = ReactDOMServer.renderToString(
BsFillMusicPlayerFill(iconStyle),
const musicIconHtml = iconWrapper(
ReactDOMServer.renderToString(BsFillMusicPlayerFill(iconStyle)),
'Music Playerへ移動する',
);

const metaTitle = 'yktakaha4.github.io';
Expand Down Expand Up @@ -108,17 +115,17 @@ const config: Config = {
{
position: 'right',
href: repositoryUrl,
html: `<div title="リポジトリを表示する">${githubIconHtml}</div>`,
html: githubIconHtml,
},
{
position: 'right',
href: pdfUrl,
html: `<div title="PDFファイルをダウンロードする">${fileDownloadIconHtml}</div>`,
html: fileDownloadIconHtml,
},
{
position: 'right',
href: `#${soundPlayerAnchor}`,
html: `<div style="margin-right: 0.4rem" title="Music Playerへ移動する">${musicIconHtml}</div>`,
html: `<div style="display: flex; margin-right: 0.35rem">${musicIconHtml}</div>`,
},
],
},
Expand Down
11 changes: 11 additions & 0 deletions pdf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/puppeteer/puppeteer:21

USER root

RUN apt-get update && apt-get install -y \
fonts-noto \
fonts-noto-extra \
fonts-noto-cjk \
fonts-noto-color-emoji

USER pptruser
12 changes: 11 additions & 1 deletion pdf/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ async function run() {
await page.goto(url, { waitUntil: 'networkidle0' });

console.log('Generating PDF...');
await page.pdf({ path: output, format: 'A4' });
await page.pdf({
path: output,
format: 'A4',
displayHeaderFooter: true,
footerTemplate:
'<div style="width: 100%; font-size: 12px; padding: 0 0.5cm; display: flex; justify-content: space-between;"><div></div><div><span class="pageNumber"></span> / <span class="totalPages"></span></div></div>',
margin: {
top: '0.4cm',
bottom: '0.8cm',
},
});

await browser.close();
console.log('Done: Generating PDF');
Expand Down
12 changes: 12 additions & 0 deletions src/components/ui/Timestamp.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { render } from '@testing-library/react';
import { Timestamp } from '@/components/ui/Timestamp';
import dayjs from 'dayjs';

describe('Timestamp', () => {
test('現在時刻が描画される', () => {
const { container } = render(<Timestamp />);
expect(container.textContent).toBe(
`内容は${dayjs().format('YYYY/M/D')}時点の情報です`,
);
});
});
6 changes: 6 additions & 0 deletions src/components/ui/Timestamp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { FC } from 'react';
import dayjs from 'dayjs';

export const Timestamp: FC = () => {
return <>内容は{dayjs().format('YYYY/M/D')}時点の情報です</>;
};
11 changes: 11 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
--ifm-footer-background-color: transparent;
}

.capy--mobile-only {
display: none;
}

@media only screen and (max-width: 997px) {
.capy--mobile-only {
display: inherit;
}
}

@media print {
* {
color: black !important;
font-family: "Noto Sans JP", sans-serif !important;
}
.badge {
border: grey solid thin !important;
Expand Down
8 changes: 6 additions & 2 deletions src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { TechArticles } from '../components/TechArticles';
import { Margin } from '../components/ui/Margin';
import { Break } from '../components/ui/Break';
import { ProfileImages } from '../components/ProfileImages';
import { Timestamp } from '../components/ui/Timestamp';

<head>
<title>yktakaha4.github.io</title>
<meta name="description" content="yktakaha4のポートフォリオサイト" />
<title>Portfolio | {contentTitle}</title>
</head>

# yktakaha4.github.io
Expand All @@ -27,6 +27,10 @@ import { ProfileImages } from '../components/ProfileImages';

## 職務経歴

<Margin>
<Timestamp />
</Margin>

### 正社員

#### 2021/1 ~ 現在 : LAPRAS株式会社
Expand Down