Skip to content

Commit

Permalink
feat: add mobilePreviewUrlParams (#630)
Browse files Browse the repository at this point in the history
* feat: add mobilePreviewUrlParams

* fix: add default value

* docs: chagnelog
  • Loading branch information
alvinhui authored Jan 22, 2024
1 parent 591d627 commit af38e3c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-docusaurus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.18

feat: add url params for mobilePreview

## 1.4.17

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-docusaurus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/pkg-plugin-docusaurus",
"version": "1.4.17",
"version": "1.4.18",
"description": "@ice/pkg plugin for component and docs preview.",
"main": "es2017/index.mjs",
"exports": {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-docusaurus/src/remark/extractCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const escapeCode = (code) => {
/**
* Remark Plugin to extract codeBlock & rendered as component
* @type {import('unified').Plugin}
* @param {options: { mobilePreview: boolean; baseUrl: string; }}
* @param {options: { mobilePreview: boolean; baseUrl: string; mobilePreviewUrlParams: string; }}
*/
const extractCodePlugin = (options) => {
const { mobilePreview = false, baseUrl = '/' } = options;
const { mobilePreview = false, baseUrl = '/', mobilePreviewUrlParams = '' } = options;

const transformer = (ast, vfile) => {
const demosMeta = [];
Expand Down Expand Up @@ -53,7 +53,7 @@ const extractCodePlugin = (options) => {
idx: index,
demoFilename,
demoFilepath,
url: path.join(baseUrl.startsWith('/') ? '' : '/', baseUrl, 'demos', demoFilename, '/'),
url: `${path.join(baseUrl.startsWith('/') ? '' : '/', baseUrl, 'demos', demoFilename, '/')}?${mobilePreviewUrlParams}`,
});
demoIndex += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-docusaurus/src/template/docusaurus.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const config = {
sidebarItemsGenerator: {{{sidebarItemsGenerator}}},
{{/if}}
remarkPlugins: [
[extractCode, { mobilePreview: {{mobilePreview}}, baseUrl: '{{baseUrl}}' }],
[extractCode, { mobilePreview: {{mobilePreview}}, baseUrl: '{{baseUrl}}', mobilePreviewUrlParams: '{{mobilePreviewUrlParams}}' }],
{{#if remarkPlugins}}
{{#each remarkPlugins}}
{{{this}}},
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-docusaurus/src/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface PluginDocusaurusOptions {
* Whether preview components of mobile styles
*/
mobilePreview?: boolean;
/**
* When mobilePreview is true, the url parameters of the mobile preview page
*/
mobilePreviewUrlParams?: string;

/**
* Default locale that does not have its name in the base URL
Expand Down

1 comment on commit af38e3c

@vercel
Copy link

@vercel vercel bot commented on af38e3c Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

icepkg – ./

icepkg-git-main-icepkg.vercel.app
icepkg.vercel.app
icepkg-icepkg.vercel.app

Please sign in to comment.