Skip to content

Commit

Permalink
feat: support html template for tabbar
Browse files Browse the repository at this point in the history
  • Loading branch information
answershuto committed Jul 20, 2022
1 parent 57a5367 commit 052fe1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/plugin-rax-pha/src/html.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover"
/>
<%- metas.join('') %> <%- links.join('') %>
<title></title>
</head>
<body>
<div id="root"></div>
</body>
<%- scripts.join('') %>
</html>
24 changes: 24 additions & 0 deletions packages/plugin-rax-pha/src/manifestHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { decamelize } = require('humps');
const pathPackage = require('path');
const { manifestRetainKeys: retainKeys, manifestCamelizeKeys: camelizeKeys } = require('./manifestWhiteList');
const ejs = require('ejs');
const fs = require('fs-extra');
const path = require('path');

// transform app config to decamelize
function transformAppConfig(appConfig, isRoot = true, parentKey) {
Expand Down Expand Up @@ -54,12 +57,33 @@ function transformAppConfig(appConfig, isRoot = true, parentKey) {
} else if (key === 'requestHeaders') {
// keys of requestHeaders should not be transformed
data[transformKey] = value;
} else if (key === 'tabBar') {
// Transform to html string by metas,links and scripts.
const { metas = [], links = [], scripts = [] } = value;

delete value['metas'];
delete value['links'];
delete value['scripts'];

const template = fs.readFileSync(path.join(__dirname, './html.ejs'), 'utf-8');
const html = ejs.render(template, {
metas,
links,
scripts,
});

data[transformKey] = {
...value,
html,
};
} else if (typeof value === 'object' && !(parentKey === 'dataPrefetch' && (key === 'header' || key === 'data'))) {
data[transformKey] = transformAppConfig(value, false, key);
} else {
data[transformKey] = value;
}
}

// console.log('data=', data);
return data;
}

Expand Down

0 comments on commit 052fe1e

Please sign in to comment.