From bb0f4b2bc5effd6e717636a4702dd5139b78e48b Mon Sep 17 00:00:00 2001 From: Franklin Koch Date: Fri, 5 Apr 2024 03:56:52 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A5=20Prefer=20frontmatter=20downloads?= =?UTF-8?q?=20over=20exports=20(#351)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * πŸ“₯ Prefer frontmatter downloads over exports * πŸ“₯ Consume additional properties of downloads * πŸ“₯ Filename is now optional on HasExports * πŸ—„added download behaviours for static, internal and external links in article-theme * πŸ”§ Update static vs. filename usage * πŸ”§ Do a better job with types from myst-config * πŸ”§ Align downloads dropdown with article theme downloads * πŸ“₯ Use triggerDirectDownload in article theme and fix types * πŸ“¦ Update myst dependencies * 🍿 Changesets * πŸ”‘ added missing key prop * ⃝ no-op --------- Co-authored-by: stevejpurves --- .changeset/dirty-rabbits-attend.md | 8 + .changeset/metal-vans-shake.md | 13 ++ package-lock.json | 170 +++++++++--------- packages/common/package.json | 6 +- packages/common/src/types.ts | 9 +- packages/common/src/utils.ts | 12 ++ packages/frontmatter/src/FrontmatterBlock.tsx | 5 +- packages/frontmatter/src/downloads.tsx | 65 +++++-- packages/jupyter/package.json | 8 +- packages/myst-demo/package.json | 18 +- packages/myst-to-react/package.json | 4 +- packages/providers/package.json | 6 +- packages/site/package.json | 6 +- themes/article/app/components/ArticlePage.tsx | 4 +- themes/article/app/components/Downloads.tsx | 82 +++++++-- themes/article/package.json | 4 +- themes/book/package.json | 4 +- 17 files changed, 281 insertions(+), 143 deletions(-) create mode 100644 .changeset/dirty-rabbits-attend.md create mode 100644 .changeset/metal-vans-shake.md diff --git a/.changeset/dirty-rabbits-attend.md b/.changeset/dirty-rabbits-attend.md new file mode 100644 index 000000000..f8acd05db --- /dev/null +++ b/.changeset/dirty-rabbits-attend.md @@ -0,0 +1,8 @@ +--- +'@myst-theme/frontmatter': patch +'@myst-theme/common': patch +'@myst-theme/article': patch +'@myst-theme/book': patch +--- + +Add downloads to supersede exports diff --git a/.changeset/metal-vans-shake.md b/.changeset/metal-vans-shake.md new file mode 100644 index 000000000..d8c15c52a --- /dev/null +++ b/.changeset/metal-vans-shake.md @@ -0,0 +1,13 @@ +--- +'myst-to-react': patch +'@myst-theme/frontmatter': patch +'myst-demo': patch +'@myst-theme/providers': patch +'@myst-theme/jupyter': patch +'@myst-theme/common': patch +'@myst-theme/article': patch +'@myst-theme/site': patch +'@myst-theme/book': patch +--- + +Update myst versions diff --git a/package-lock.json b/package-lock.json index 4ddf114ee..64ee735e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28532,9 +28532,9 @@ "integrity": "sha512-s9+rcClLmZsZc3YL8Awjg/YO/VdphlE20LJ9Bx5a8RAFLI5a1vq6Mll8kOzG6w/wy8yhFLBupaa6Mfd60GATkA==" }, "node_modules/markdown-it-myst": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/markdown-it-myst/-/markdown-it-myst-1.0.5.tgz", - "integrity": "sha512-G1V4BsElSxjjvYGBrNTs1k3Vn3igk1umEW7p8k7xxazw3PAZ8CWwmZVyCAGrGmqJu/cDy2NbifecxYovK8qyUA==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/markdown-it-myst/-/markdown-it-myst-1.0.7.tgz", + "integrity": "sha512-AxMF66x4D4Mjn2UgkmE6cZwTyRoBfgotf4/wNVYxPeLnIT4tPfECYT0/AeBmH6Qrw5cZydDty0ch5qi5LF96LQ==", "dependencies": { "js-yaml": "^4.1.0", "markdown-it": "^13.0.1", @@ -30396,12 +30396,12 @@ } }, "node_modules/myst-common": { - "version": "1.1.31", - "resolved": "https://registry.npmjs.org/myst-common/-/myst-common-1.1.31.tgz", - "integrity": "sha512-Pbvuv0usD1DaCwiVgYcTUEyPnrh6rXWnmkpSvTNDYGwF05mPS8wAkXPFYX7jO3NSZvA0ZjnnGGPHPo2mK5V2wg==", + "version": "1.1.34", + "resolved": "https://registry.npmjs.org/myst-common/-/myst-common-1.1.34.tgz", + "integrity": "sha512-B7l/jL5lVGmRRnTOd3xM+tulifqYpCdGgVcl+9O5/o9S4NDW6oh2jwmuECD87sppxYQsDR/yTJ5L7RYQizCzhw==", "dependencies": { "mdast": "^3.0.0", - "myst-frontmatter": "^1.1.31", + "myst-frontmatter": "^1.1.34", "myst-spec": "^0.0.5", "nanoid": "^4.0.0", "unified": "^10.1.2", @@ -30412,11 +30412,11 @@ } }, "node_modules/myst-config": { - "version": "1.1.31", - "resolved": "https://registry.npmjs.org/myst-config/-/myst-config-1.1.31.tgz", - "integrity": "sha512-Q0AX8ojQrknVnz1aDGUtDjPCun2WicMLnpMpfcaSplFrVopdVD9Qh8AOi2htRTWHnAPw/Q5keMH2pu7GLJ4Zpw==", + "version": "1.1.34", + "resolved": "https://registry.npmjs.org/myst-config/-/myst-config-1.1.34.tgz", + "integrity": "sha512-F/r9m4idWDUZwEXzy+Ky0/v+Vw4/8mTBf9O9ZwFJtkkXp3V1vmTV9arOUIcigx7HfT7V27jLboKcyMo/4kW6Tg==", "dependencies": { - "myst-frontmatter": "^1.1.31", + "myst-frontmatter": "^1.1.34", "simple-validators": "^1.0.4" } }, @@ -30425,14 +30425,14 @@ "link": true }, "node_modules/myst-directives": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/myst-directives/-/myst-directives-1.2.0.tgz", - "integrity": "sha512-+crEUZfl9EURdFBh9H0QvaipUaT8l0OK8yIDSK94hlEd3XA+uW+UOvm35EOpjp02Lh3kUa6IPfqgLlhhDVJ2mg==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/myst-directives/-/myst-directives-1.2.2.tgz", + "integrity": "sha512-zowLXse+aZhA9cv5nO5xkef2gVhLo3ZZNLQJH0W8eLFm6+isE8Kz32on7y30+twq/KFZP32762iO4ZJRVm8mcA==", "dependencies": { "classnames": "^2.3.2", "js-yaml": "^4.1.0", - "myst-common": "^1.1.31", - "myst-spec-ext": "^1.1.31", + "myst-common": "^1.1.34", + "myst-spec-ext": "^1.1.34", "nanoid": "^4.0.2", "unist-util-select": "^4.0.3", "vfile": "^5.3.7" @@ -30496,9 +30496,9 @@ } }, "node_modules/myst-frontmatter": { - "version": "1.1.31", - "resolved": "https://registry.npmjs.org/myst-frontmatter/-/myst-frontmatter-1.1.31.tgz", - "integrity": "sha512-f5b7HnohJuqh2pbi82J8APhpoDm9yRWMccROIACqZEL8CK5FSCE2lnxMXzrA2kIEcCBg7LynYc/Ecg1wbgVqsw==", + "version": "1.1.34", + "resolved": "https://registry.npmjs.org/myst-frontmatter/-/myst-frontmatter-1.1.34.tgz", + "integrity": "sha512-O5254NKayYxOjZtbywtpq6egdH5jpvNU04kDIH+S/qNQXvXgMwZ6knh160UskLSBqjr8KHpBU3fbjp/ZQJ1pQg==", "dependencies": { "credit-roles": "^2.1.0", "doi-utils": "^2.0.0", @@ -30508,9 +30508,9 @@ } }, "node_modules/myst-parser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/myst-parser/-/myst-parser-1.2.0.tgz", - "integrity": "sha512-NXz/fXzd1ZJ57qg3WbKywWwviXjYcFVQjCm+0TbTALOkuOSAJtsxRE9JXX8b3/LkZurFXqKTPlLBHlriSKiO1g==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/myst-parser/-/myst-parser-1.2.2.tgz", + "integrity": "sha512-laIsMg+SVZX166gwr8Vtx1DjvPrTBkFT+KepwQPKbApHrjSpYuxTphSADGB/xFQfh/idqBnSZBGk5E+lDTe+cQ==", "dependencies": { "he": "^1.2.0", "markdown-it": "^12.3.2", @@ -30519,12 +30519,12 @@ "markdown-it-dollarmath": "^0.5.0", "markdown-it-footnote": "^3.0.3", "markdown-it-front-matter": "^0.2.3", - "markdown-it-myst": "1.0.5", + "markdown-it-myst": "1.0.7", "markdown-it-myst-extras": "0.3.0", "markdown-it-task-lists": "^2.1.1", - "myst-common": "^1.1.31", - "myst-directives": "^1.2.0", - "myst-roles": "^1.2.0", + "myst-common": "^1.1.34", + "myst-directives": "^1.2.2", + "myst-roles": "^1.2.2", "myst-spec": "^0.0.5", "unified": "^10.1.1", "unist-builder": "^3.0.0", @@ -30535,12 +30535,12 @@ } }, "node_modules/myst-roles": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/myst-roles/-/myst-roles-1.2.0.tgz", - "integrity": "sha512-Tu+50zgyHdpYVEzObUws43pgJAYMnyHw1YqkPIvFC/kbLxrKuRsKuxSrQ8156eF8YrnKCrNPy80kEn7Q9IR6oA==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/myst-roles/-/myst-roles-1.2.2.tgz", + "integrity": "sha512-0oFEFgh/XL9rMgL7lGN+2kSXsTWvQsjFs5Vy8kJxCx/4qvHhdGJNg36MeLeYNfepiFlHqyGSzH+zk2W5Qsu+Zw==", "dependencies": { - "myst-common": "^1.1.31", - "myst-spec-ext": "^1.1.31" + "myst-common": "^1.1.34", + "myst-spec-ext": "^1.1.34" } }, "node_modules/myst-spec": { @@ -30549,9 +30549,9 @@ "integrity": "sha512-L/4TV1l5ZbWUOgSnXqiYrx192SV4I+HqjX7TBQ4k02/heeNFckpkUIyLulraap5heTyLcJs8UYBxu+Kv5JiiRw==" }, "node_modules/myst-spec-ext": { - "version": "1.1.31", - "resolved": "https://registry.npmjs.org/myst-spec-ext/-/myst-spec-ext-1.1.31.tgz", - "integrity": "sha512-qvlfseMT2JwbAbTWOVHBMlCSdPwmv0cSppKGOukSkBcKYYip9wZGsGIR0px/eTOj3ze83RhQLp0jZNy2o4LXUQ==", + "version": "1.1.34", + "resolved": "https://registry.npmjs.org/myst-spec-ext/-/myst-spec-ext-1.1.34.tgz", + "integrity": "sha512-VWhfkkGQeQ8X6n5mc8lbYm7zasDObKP41nP/ono/zPq5Ah0Dq8p6WnckJbiJNzQmmtZp5UFS+R/+RtZBhclF5Q==", "dependencies": { "myst-spec": "^0.0.5" } @@ -30571,9 +30571,9 @@ } }, "node_modules/myst-to-html": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/myst-to-html/-/myst-to-html-1.2.0.tgz", - "integrity": "sha512-gQg2evW/9cRTBd5XDgZGGgVd9s9Tv2sImRThM1qYKBnpelIl53XXbnRQpqbD4dSBzreENYiknXNkIh7rocKZDg==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/myst-to-html/-/myst-to-html-1.2.2.tgz", + "integrity": "sha512-e9REFk4eHsHjMIMDl16Pl9qWP6hxI3fyCzTEuRZNyBxggVnDQOc1I/bQ3xpeUEAL7acTfswwEEp2dqE89Q7e7g==", "dependencies": { "classnames": "^2.3.2", "hast": "^1.0.0", @@ -30582,7 +30582,7 @@ "mdast": "^3.0.0", "mdast-util-find-and-replace": "^2.1.0", "mdast-util-to-hast": "^12.3.0", - "myst-common": "^1.1.31", + "myst-common": "^1.1.34", "rehype-format": "^4.0.1", "rehype-parse": "^8.0.4", "rehype-remark": "^9.1.2", @@ -30664,36 +30664,36 @@ "link": true }, "node_modules/myst-to-tex": { - "version": "1.0.23", - "resolved": "https://registry.npmjs.org/myst-to-tex/-/myst-to-tex-1.0.23.tgz", - "integrity": "sha512-4eacbgp9BRSKoeJAk7mzhw55RPPXVDS1unJ+vu9zwiJcQeVTIS7f0GV6Nj0jpBnjaJYA24cd4Ds+GFx4AgU/lw==", + "version": "1.0.25", + "resolved": "https://registry.npmjs.org/myst-to-tex/-/myst-to-tex-1.0.25.tgz", + "integrity": "sha512-+GwZgNdNO3PAzI/5RCK1NpU9fcD2eVaOYMeydgGzL1GYgsbPmpzwHIllB5DmGj1N747DJCWTyZFUAz3dct8RLQ==", "dependencies": { - "myst-common": "^1.1.31", + "myst-common": "^1.1.34", "myst-ext-proof": "^1.0.8", - "myst-frontmatter": "^1.1.31", - "myst-spec-ext": "^1.1.31", + "myst-frontmatter": "^1.1.34", + "myst-spec-ext": "^1.1.34", "unist-util-remove": "^3.1.0", "unist-util-select": "^4.0.3", "vfile-reporter": "^7.0.4" } }, "node_modules/myst-to-typst": { - "version": "0.0.12", - "resolved": "https://registry.npmjs.org/myst-to-typst/-/myst-to-typst-0.0.12.tgz", - "integrity": "sha512-o4xWZ0M4PmRjKPKEAAGhmgJ5tYrgbnuIZu0234wtDQpEvtK+Qt/xngMd3bEJhhG2HuC4qadcGLkzzm+fWh08Lg==", + "version": "0.0.13", + "resolved": "https://registry.npmjs.org/myst-to-typst/-/myst-to-typst-0.0.13.tgz", + "integrity": "sha512-Ki7Ujno5vETiJS5ZskOj0mLSKewh9ZLnlz0Xa6nHGGf86YPLmH1fS8beGVLx4jMlEE00kIPjzDTcZJzYEIqWjw==", "dependencies": { - "myst-common": "^1.1.31", - "myst-frontmatter": "^1.1.31", - "myst-spec-ext": "^1.1.31", + "myst-common": "^1.1.34", + "myst-frontmatter": "^1.1.34", + "myst-spec-ext": "^1.1.34", "tex-to-typst": "^0.0.5", "unist-util-select": "^4.0.3", "vfile-reporter": "^7.0.4" } }, "node_modules/myst-transforms": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/myst-transforms/-/myst-transforms-1.3.1.tgz", - "integrity": "sha512-9mcJVKMZ/oHt0nU2x+Yq1WIZ/bIef0WS7n73gJiRWp6iPV957KBuQnqZOmnB2MXQNwSo4io6MxfvPpAA6eZ3yA==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/myst-transforms/-/myst-transforms-1.3.3.tgz", + "integrity": "sha512-QvUHOqKEspAINwyP6M4pM8QMqwWCziT7IsUxMTgSN+FhmbDyMS6Jcf4a24D2A5FjPrbOW9829IBvvd0mRaBn5A==", "dependencies": { "doi-utils": "^2.0.0", "hast-util-from-html": "^2.0.1", @@ -30702,11 +30702,11 @@ "js-yaml": "^4.1.0", "katex": "^0.15.2", "mdast-util-find-and-replace": "^2.1.0", - "myst-common": "^1.1.31", - "myst-frontmatter": "^1.1.31", + "myst-common": "^1.1.34", + "myst-frontmatter": "^1.1.34", "myst-spec": "^0.0.5", - "myst-spec-ext": "^1.1.31", - "myst-to-html": "1.2.0", + "myst-spec-ext": "^1.1.34", + "myst-to-html": "1.2.2", "rehype-parse": "^8.0.4", "rehype-remark": "^9.1.2", "unified": "^10.0.0", @@ -39418,9 +39418,9 @@ "version": "0.8.0", "license": "MIT", "dependencies": { - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", - "myst-spec-ext": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", + "myst-spec-ext": "^1.1.34", "nbtx": "^0.2.3", "unist-util-select": "^4.0.3" } @@ -39500,11 +39500,11 @@ "buffer": "^6.0.3", "classnames": "^2.3.2", "jupyterlab-plotly": "^5.18.0", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", - "myst-frontmatter": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", + "myst-frontmatter": "^1.1.34", "myst-spec": "^0.0.5", - "myst-spec-ext": "^1.1.31", + "myst-spec-ext": "^1.1.34", "myst-to-react": "^0.8.0", "nanoid": "^4.0.2", "nbtx": "^0.2.3", @@ -39555,24 +39555,24 @@ "@heroicons/react": "^2.0.18", "classnames": "^2.3.2", "js-yaml": "^4.1.0", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", - "myst-directives": "^1.2.0", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", + "myst-directives": "^1.2.2", "myst-ext-card": "^1.0.5", "myst-ext-exercise": "^1.0.5", "myst-ext-grid": "^1.0.5", "myst-ext-proof": "^1.0.8", "myst-ext-tabs": "^1.0.5", - "myst-frontmatter": "^1.1.31", - "myst-parser": "^1.2.0", + "myst-frontmatter": "^1.1.34", + "myst-parser": "^1.2.2", "myst-spec": "^0.0.5", "myst-to-docx": "^1.0.9", - "myst-to-html": "^1.2.0", + "myst-to-html": "^1.2.2", "myst-to-jats": "^1.0.24", "myst-to-react": "^0.8.0", - "myst-to-tex": "^1.0.23", - "myst-to-typst": "^0.0.12", - "myst-transforms": "^1.3.1", + "myst-to-tex": "^1.0.25", + "myst-to-typst": "^0.0.13", + "myst-transforms": "^1.3.3", "unified": "^10.1.2", "unist-util-remove": "^4.0.0", "unist-util-visit": "^4.1.2", @@ -39661,8 +39661,8 @@ "@radix-ui/react-hover-card": "^1.0.6", "buffer": "^6.0.3", "classnames": "^2.3.2", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", "myst-spec": "^0.0.5", "nanoid": "^4.0.2", "react-syntax-highlighter": "^15.5.0", @@ -39720,9 +39720,9 @@ "peerDependencies": { "@types/react": "^16.8 || ^17.0 || ^18.0", "@types/react-dom": "^16.8 || ^17.0 || ^18.0", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", - "myst-frontmatter": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", + "myst-frontmatter": "^1.1.34", "react": "^16.8 || ^17.0 || ^18.0", "react-dom": "^16.8 || ^17.0 || ^18.0" } @@ -39742,10 +39742,10 @@ "@radix-ui/react-collapsible": "^1.0.3", "classnames": "^2.3.2", "lodash.throttle": "^4.1.1", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", "myst-demo": "^0.8.0", - "myst-spec-ext": "^1.1.31", + "myst-spec-ext": "^1.1.34", "myst-to-react": "^0.8.0", "nbtx": "^0.2.3", "node-cache": "^5.1.2", @@ -39793,8 +39793,8 @@ "@remix-run/node": "~1.17.0", "@remix-run/react": "~1.17.0", "@remix-run/vercel": "~1.17.0", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", "node-fetch": "^2.6.11", "react": "^18.2.0", "react-dom": "^18.2.0" @@ -39826,8 +39826,8 @@ "@remix-run/node": "~1.17.0", "@remix-run/react": "~1.17.0", "@remix-run/vercel": "~1.17.0", - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", "node-fetch": "^2.6.11", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/packages/common/package.json b/packages/common/package.json index 5b6f9e03e..a3b7f1126 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -19,9 +19,9 @@ "build": "npm-run-all -l clean -p build:esm" }, "dependencies": { - "myst-common": "^1.1.31", - "myst-config": "^1.1.31", - "myst-spec-ext": "^1.1.31", + "myst-common": "^1.1.34", + "myst-config": "^1.1.34", + "myst-spec-ext": "^1.1.34", "nbtx": "^0.2.3", "unist-util-select": "^4.0.3" } diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 28b9ba0dd..6195aed8d 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -1,6 +1,6 @@ import type { Dependency, SourceFileKind } from 'myst-spec-ext'; import type { GenericParent, References } from 'myst-common'; -import type { SiteManifest } from 'myst-config'; +import type { SiteAction, SiteExport, SiteManifest } from 'myst-config'; import type { PageFrontmatter } from 'myst-frontmatter'; export enum Theme { @@ -44,6 +44,11 @@ export type FooterLinks = { }; }; +type PageFrontmatterWithDownloads = Omit & { + downloads?: SiteAction[]; + exports?: SiteExport[]; +}; + export type PageLoader = { kind: SourceFileKind; location: string; @@ -51,7 +56,7 @@ export type PageLoader = { slug: string; domain: string; // This is written in at render time in the site project: string; // This is written in at render time in the site - frontmatter: PageFrontmatter; + frontmatter: PageFrontmatterWithDownloads; mdast: GenericParent; references: References; footer?: FooterLinks; diff --git a/packages/common/src/utils.ts b/packages/common/src/utils.ts index 73579e02e..c5908ecef 100644 --- a/packages/common/src/utils.ts +++ b/packages/common/src/utils.ts @@ -142,6 +142,12 @@ export function updateSiteManifestStaticLinksInplace( return { ...exp, url: updateUrl(exp.url) }; }); } + if (project?.downloads) { + project.downloads = project.downloads.map((exp) => { + if (!exp.url || !exp.static) return exp; + return { ...exp, url: updateUrl(exp.url) }; + }); + } project.pages .filter((page): page is ManifestProjectItem => 'slug' in page) .forEach((page) => { @@ -171,6 +177,12 @@ export function updatePageStaticLinksInplace(data: PageLoader, updateUrl: Update return { ...exp, url: updateUrl(exp.url) }; }); } + if (data?.frontmatter?.downloads) { + data.frontmatter.downloads = data.frontmatter.downloads.map((exp) => { + if (!exp.url || !exp.static) return exp; + return { ...exp, url: updateUrl(exp.url) }; + }); + } // Fix all of the images to point to the CDN const images = selectAll('image', data.mdast) as Image[]; images.forEach((node) => { diff --git a/packages/frontmatter/src/FrontmatterBlock.tsx b/packages/frontmatter/src/FrontmatterBlock.tsx index 58c9e2ed2..3cbfcdc64 100644 --- a/packages/frontmatter/src/FrontmatterBlock.tsx +++ b/packages/frontmatter/src/FrontmatterBlock.tsx @@ -206,11 +206,12 @@ export function FrontmatterBlock({ venue, biblio, exports, + downloads, date, authors, } = frontmatter; const isJupyter = kind === SourceFileKind.Notebook; - const hasExports = exports && exports.length > 0; + const hasExports = downloads ? downloads.length > 0 : exports && exports.length > 0; const hasAuthors = authors && authors.length > 0; const hasBadges = !!open_access || !!license || !!hasExports || !!isJupyter || !!github; const hasHeaders = !!subject || !!venue || !!biblio; @@ -251,7 +252,7 @@ export function FrontmatterBlock({ )} )} - {!hideExports && } + {!hideExports && } )} {title &&

{title}

} diff --git a/packages/frontmatter/src/downloads.tsx b/packages/frontmatter/src/downloads.tsx index 467cc862e..e04f75176 100644 --- a/packages/frontmatter/src/downloads.tsx +++ b/packages/frontmatter/src/downloads.tsx @@ -1,10 +1,16 @@ import { Menu } from '@headlessui/react'; -import { DocumentIcon, ArrowDownTrayIcon } from '@heroicons/react/24/outline'; +import { + DocumentIcon, + ArrowDownTrayIcon, + ArrowTopRightOnSquareIcon, + DocumentArrowDownIcon, +} from '@heroicons/react/24/outline'; import classNames from 'classnames'; +import type { SiteAction, SiteExport } from 'myst-config'; import { useCallback } from 'react'; type HasExports = { - exports?: { format: string; filename: string; url: string }[]; + exports?: SiteExport[] | SiteAction[]; }; /** @@ -61,12 +67,45 @@ export function Download({ filename, format, className, + title, + internal, }: { url: string; - filename: string; - format: string; + filename?: string; + format?: string; className?: string; + title?: string; + internal?: boolean; }) { + if (!filename) { + const icon = internal ? ( +