Skip to content

Commit 28645e8

Browse files
committed
feat: copy the latest docu-notion-styles.css to output
Then it will be available to point to each site's docusaurus.config.js
1 parent 4b6e33a commit 28645e8

File tree

3 files changed

+92
-63
lines changed

3 files changed

+92
-63
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"// test out with a private sample notion db": "",
1414
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr --log-level debug",
1515
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
16+
"pull-test-css": "npm run ts -- --css-output-directory ./test/css -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
1617
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
1718
"// test with a semi-stable/public site:": "",
1819
"pull-sample": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --locales en,es,fr,de --log-level verbose",
Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,60 @@
1-
/* Note, I haven't figure out how a Docusaurus app can actually include this, yet.
2-
So currently this has to be duplicated by the client.
3-
*/
4-
5-
/* Copied from
6-
https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/styles.css#L934
7-
and
8-
https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/styles.css#L1063
9-
*/
10-
.notion-column {
11-
display: flex;
12-
flex-direction: column;
13-
padding-top: 12px;
14-
padding-bottom: 12px;
15-
}
16-
17-
.notion-column > *:first-child {
18-
margin-top: 0;
19-
margin-left: 0;
20-
margin-right: 0;
21-
}
22-
23-
.notion-column > *:last-child {
24-
margin-left: 0;
25-
margin-right: 0;
26-
margin-bottom: 0;
27-
}
28-
29-
.notion-row {
30-
display: flex;
31-
overflow: hidden;
32-
width: 100%;
33-
max-width: 100%;
34-
}
35-
36-
@media (max-width: 640px) {
37-
.notion-row {
38-
flex-direction: column;
39-
}
40-
41-
.notion-row .notion-column {
42-
width: 100% !important;
43-
}
44-
45-
.notion-row .notion-spacer {
46-
display: none;
47-
}
48-
}
49-
50-
.notion-spacer {
51-
/* This matches the value in ColumnTransformer.ts */
52-
width: calc(min(32px, 4vw));
53-
}
54-
55-
.notion-spacer:last-child {
56-
display: none;
57-
}
58-
/* End copied from NotionX */
1+
/* This should be added to the docusaurus.config.js in order to show some notion things correctly.
2+
See the option: --css-output-directory
3+
See the docusaurus docs: https://docusaurus.io/docs/styling-layout
4+
See the use in the docu-notion-sample-site: https://github.com/sillsdev/docu-notion-sample-site/blob/main/docusaurus.config.js
5+
*/
6+
7+
/* Copied from
8+
https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/styles.css#L934
9+
and
10+
https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/styles.css#L1063
11+
*/
12+
.notion-column {
13+
display: flex;
14+
flex-direction: column;
15+
padding-top: 12px;
16+
padding-bottom: 12px;
17+
}
18+
19+
.notion-column > *:first-child {
20+
margin-top: 0;
21+
margin-left: 0;
22+
margin-right: 0;
23+
}
24+
25+
.notion-column > *:last-child {
26+
margin-left: 0;
27+
margin-right: 0;
28+
margin-bottom: 0;
29+
}
30+
31+
.notion-row {
32+
display: flex;
33+
overflow: hidden;
34+
width: 100%;
35+
max-width: 100%;
36+
}
37+
38+
@media (max-width: 640px) {
39+
.notion-row {
40+
flex-direction: column;
41+
}
42+
43+
.notion-row .notion-column {
44+
width: 100% !important;
45+
}
46+
47+
.notion-row .notion-spacer {
48+
display: none;
49+
}
50+
}
51+
52+
.notion-spacer {
53+
/* This matches the value in ColumnTransformer.ts */
54+
width: calc(min(32px, 4vw));
55+
}
56+
57+
.notion-spacer:last-child {
58+
display: none;
59+
}
60+
/* End copied from NotionX */

src/run.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import * as fs from "fs-extra";
12
import { Option, program } from "commander";
23
import { setLogLevel } from "./log";
34

4-
import { notionPull, DocuNotionOptions } from "./pull";
5+
import { notionPull } from "./pull";
6+
import path from "path";
57

6-
export function run() {
8+
export async function run(): Promise<void> {
79
const pkg = require("../package.json");
810
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
911
console.log(`docu-notion version ${pkg.version}`);
@@ -21,9 +23,14 @@ export function run() {
2123
)
2224
.option(
2325
"-m, --markdown-output-path <string>",
24-
"Root of the hierarchy for md files. WARNING: node-pull-mdx will delete files from this directory. Note also that if it finds localized images, it will create an i18n/ directory as a sibling.",
26+
"Root of the hierarchy for md files. WARNING: docu-notion will delete files from this directory. Note also that if it finds localized images, it will create an i18n/ directory as a sibling.",
2527
"./docs"
2628
)
29+
.option(
30+
"--css-output-directory <string>",
31+
"docu-notion has a docu-notion-styles.css file that you will need to use to get things like notion columns to look right. This option specifies where that file should be copied to.",
32+
"./css"
33+
)
2734
.option(
2835
"-t, --status-tag <string>",
2936
"Database pages without a Notion page property 'status' matching this will be ignored. Use '*' to ignore status altogether.",
@@ -54,8 +61,27 @@ export function run() {
5461
program.showHelpAfterError();
5562
program.parse();
5663
setLogLevel(program.opts().logLevel);
57-
console.log(JSON.stringify(program.opts));
58-
notionPull(program.opts() as DocuNotionOptions).then(() =>
64+
console.log(JSON.stringify(program.opts()));
65+
66+
// copy in the this version of the css needed to make columns (and maybe other things?) work
67+
let pathToCss = "";
68+
try {
69+
pathToCss = require.resolve(
70+
"@sillsdev/docu-notion/dist/docu-notion-styles.css"
71+
);
72+
} catch (e) {
73+
// when testing from the docu-notion project itself:
74+
pathToCss = "./src/css/docu-notion-styles.css";
75+
}
76+
// make any missing parts of the path exist
77+
fs.ensureDirSync(program.opts().cssOutputDirectory);
78+
fs.copyFileSync(
79+
pathToCss,
80+
path.join(program.opts().cssOutputDirectory, "docu-notion-styles.css")
81+
);
82+
83+
// pull and convert
84+
await notionPull(program.opts()).then(() =>
5985
console.log("docu-notion Finished.")
6086
);
6187
}

0 commit comments

Comments
 (0)