Skip to content

Commit

Permalink
feat: add config (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng authored Aug 14, 2022
1 parent 5f31c1c commit 1d36c7d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
15 changes: 8 additions & 7 deletions app/controller/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ const safeGet = require('lodash/get');

class HomeController extends Controller {
async index() {
const ctx = this.ctx;
const { ctx, app } = this;
const user = ctx.session.user;
const { appid, callbackUrl } = ctx.app.config.authorize.dingtalkAuth;
const siteConfig = await this.ctx.model.Config.findOne({ raw: true });
const siteConfig = await ctx.model.Config.findOne({ raw: true });
const assetsUrl = safeGet(siteConfig, 'data.site.assetsUrl');
ctx.body = await this.app.render({
ctx.body = await app.render({
dingtalkAuth: {
appid,
callbackUrl,
},
user,
}, {
title: 'Reliable Suites for Macaca',
title: `${app.config.site.name || 'Reliable'} | Reliable Suites for Macaca`,
pageId: 'home',
SERVER_ADDRESS: this.config.reliableView.serverUrl,
assetsUrl: assetsUrl || this.config.reliableView.assetsUrl,
version: this.app.config.pkg.version,
SERVER_ADDRESS: app.config.reliableView.serverUrl,
assetsUrl: assetsUrl || app.config.reliableView.assetsUrl,
version: app.config.pkg.version,
siteConfig: app.config.site,
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ config.static = {
dir: path.resolve(__dirname, '..', 'view', distDirName),
};

config.site = {
logo: 'https://macacajs.github.io/reliable/logo/reliable.svg',
name: 'Reliable',
links: {
document: 'https://macacajs.github.io/reliable',
issues: 'https://github.com/macacajs/reliable/issues?utf8=%E2%9C%93&q=',
},
};

module.exports = config;
4 changes: 0 additions & 4 deletions view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"public/*.css"
],
"private": true,
"links": {
"issues": "https://github.com/macacajs/reliable/issues?utf8=%E2%9C%93&q=",
"document": "https://macacajs.github.io/reliable"
},
"scripts": {
"dev": "cross-env NODE_ENV=development webpack serve",
"dev:test": "NODE_ENV=test npm run dev",
Expand Down
14 changes: 5 additions & 9 deletions view/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { LANG_LIST as langList } from '../constants/index';
const nickName = safeGet(window, 'context.user.nick');
const Header = Layout.Header;

const pkg = require('../../package.json');
const { siteConfig } = window.pageConfig;

function ContentHeader (props) {
const toggle = () => {
Expand Down Expand Up @@ -84,27 +84,23 @@ function ContentHeader (props) {
<Tooltip title={<FormattedMessage id='header.document' />}>
<a
target="_blank"
href={ pkg.links.document }
href={ siteConfig.links.document }
>
<BookOutlined />
</a>
</Tooltip>
<Tooltip title={<FormattedMessage id='header.issues' />}>
<a
target="_blank"
href={ pkg.links.issues }
href={ siteConfig.links.issues }
>
<QuestionCircleOutlined />
</a>
</Tooltip>
<Dropdown overlay={menu} placement="topCenter">
<a
rel="noopener noreferrer"
target="_blank"
href={ pkg.links.issues }
>
<span style={{ margin: 8, color: '#1890ff', cursor: 'pointer' }}>
<GlobalOutlined />
</a>
</span>
</Dropdown>
{
nickName && <Dropdown overlay={
Expand Down
9 changes: 5 additions & 4 deletions view/src/components/SiderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { FormattedMessage } from 'react-intl';

const Sider = Layout.Sider;

const { siteConfig } = window.pageConfig;

export default class SiderBar extends React.Component {
handleMenuClick (e) {
this.setState({
Expand All @@ -27,17 +29,16 @@ export default class SiderBar extends React.Component {
<Sider
trigger={null}
collapsible
width="200px"
theme="light"
collapsed={this.props.collapsed}
>
<div className="logo">
<Link to="/">
<img alt="logo" src="https://macacajs.github.io/reliable/logo/reliable.svg" />
<h1>Reliable</h1>
<img alt="logo" src={siteConfig.logo} />
<h1>{siteConfig.name}</h1>
</Link>
</div>
<Menu
theme="dark"
mode="inline"
defaultSelectedKeys={[location.pathname]}
defaultOpenKeys={[location.pathname]}
Expand Down
3 changes: 1 addition & 2 deletions view/src/components/header.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
line-height: 64px;
padding-left: 24px;
transition: all .3s;
background: #002140;
overflow: hidden;

a {
Expand All @@ -24,10 +23,10 @@

img {
width: 32px;
border-radius: 4px;
}

h1 {
color: #fff;
font-size: 20px;
margin: 0 0 0 12px;
font-family: "Myriad Pro", "Helvetica Neue", Arial, Helvetica, sans-serif;
Expand Down

0 comments on commit 1d36c7d

Please sign in to comment.