Skip to content

Commit

Permalink
Merge pull request otale#426 from dongm2ez/feature/publie_CDN
Browse files Browse the repository at this point in the history
✨add public CDN resources switch
  • Loading branch information
hellokaton authored Aug 15, 2018
2 parents 8bcbdf6 + cfa8dd2 commit 3a0b354
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/tale/bootstrap/TaleConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ public class TaleConst {
public static final String OPTION_SITE_THEME = "site_theme";
public static final String OPTION_ALLOW_INSTALL = "allow_install";
public static final String OPTION_ALLOW_COMMENT_AUDIT = "allow_comment_audit";
public static final String OPTION_ALLOW_CLOUD_CDN = "allow_cloud_CDN";
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ public RestResponse<?> saveAdvance(AdvanceParam advanceParam) {
optionsService.saveOption(OPTION_ALLOW_COMMENT_AUDIT, advanceParam.getAllowCommentAudit());
TaleConst.OPTIONS.set(OPTION_ALLOW_COMMENT_AUDIT, advanceParam.getAllowCommentAudit());
}

// 是否允许公共资源CDN
if (StringKit.isNotBlank(advanceParam.getAllowCloudCDN())) {
optionsService.saveOption(OPTION_ALLOW_CLOUD_CDN, advanceParam.getAllowCloudCDN());
TaleConst.OPTIONS.set(OPTION_ALLOW_CLOUD_CDN, advanceParam.getAllowCloudCDN());
}
return RestResponse.ok();
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/tale/extension/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public static String site_subtitle() {
return site_option("site_subtitle");
}

/**
* 是否允许使用云公共静态资源
*
* @return
*/
public static String allow_cloud_CDN() {
return site_option("allow_cloud_CDN");
}

/**
* 网站配置项
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/tale/model/params/AdvanceParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class AdvanceParam {
private String cdnURL;
private String allowInstall;
private String allowCommentAudit;
private String allowCloudCDN;

}
14 changes: 14 additions & 0 deletions src/main/resources/templates/admin/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<meta content="${_csrf_token}" name="csrf_token"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="shortcut icon" href="/static/admin/images/favicon.png"/>
#if(allow_cloud_CDN() == "true")
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/limonte-sweetalert2/6.4.1/sweetalert2.min.css" rel="stylesheet">
<link href="${cdnURL()}/plugins/vue-loading/vue-loading.min.css" rel="stylesheet">
<link href="${cdnURL()}/css/style.min.css?v=${version}" rel="stylesheet" >
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.0/respond.min.js"></script>
<![endif]-->
#else
<link href="${cdnURL()}/plugins/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="${cdnURL()}/plugins/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="${cdnURL()}/plugins/limonte-sweetalert2/6.4.1/sweetalert2.min.css" rel="stylesheet">
Expand All @@ -19,6 +32,7 @@
<script src="${cdnURL()}/plugins/html5shiv/3.7.0/html5shiv.js"></script>
<script src="${cdnURL()}/plugins/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
#end
</head>
<body class="fixed-left">
<div id="wrapper">
Expand Down
24 changes: 23 additions & 1 deletion src/main/resources/templates/admin/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3 class="panel-title">高级选项设置</h3>
<label class="col-md-3 control-label">CND地址</label>
<div class="col-md-9">
<input type="text" class="form-control" name="cdnURL" placeholder="CDN地址" />
<span class="help-block"><small>该地址用于加载博客后台静态资源不清楚请勿设置。</small></span>
<span class="help-block"><small>该地址用于加载博客后台静态资源不清楚请勿设置开启公共CDN选项时此配置无效</small></span>
</div>
</div>

Expand Down Expand Up @@ -110,8 +110,16 @@ <h3 class="panel-title">高级选项设置</h3>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label">云公共CDN资源</label>
<div class="col-md-9">
<div id="allowCloudCDN" class="toggle toggle-success"></div>
</div>
</div>

<input type="hidden" name="allowInstall" v-model="allowInstall"/>
<input type="hidden" name="allowCommentAudit" v-model="allowCommentAudit"/>
<input type="hidden" name="allowCloudCDN" v-model="allowCloudCDN"/>

<div class="clearfix pull-right">
<button type="button" class="btn btn-inverse waves-effect waves-light" @click="saveAdvanced">
Expand All @@ -137,6 +145,7 @@ <h3 class="panel-title">高级选项设置</h3>
options: {},
allowInstall: '',
allowCommentAudit: '',
allowCloudCDN: '',
isLoading: true
},
beforeCreate: function(){
Expand All @@ -154,6 +163,7 @@ <h3 class="panel-title">高级选项设置</h3>
$vm.options = data.payload;
$vm.allowInstall = data.payload.allow_install;
$vm.allowCommentAudit = data.payload.allow_comment_audit;
$vm.allowCloudCDN = data.payload.allow_cloud_CDN;

$('#allowInstall').toggles({
on: $vm.allowInstall === 'true',
Expand All @@ -171,6 +181,14 @@ <h3 class="panel-title">高级选项设置</h3>
}
});

$('#allowCloudCDN').toggles({
on: $vm.allowCloudCDN === 'true',
text: {
on: '开启',
off: '关闭'
}
});

},
error: function (error) {
console.log(error);
Expand Down Expand Up @@ -220,6 +238,10 @@ <h3 class="panel-title">高级选项设置</h3>
vm.allowCommentAudit = active;
});

$('#allowCloudCDN').on('toggle', function (e, active) {
vm.allowCloudCDN = active;
});

$(document).ready(function () {
vm.isLoading = false;
vueLoding.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<title>${head_title()}</title>
<link href="${theme_url('/static/css/xcode.min.css')}" rel="stylesheet">
<link href="${theme_url('/static/css/style.min.css')}" rel="stylesheet">
#if(allow_cloud_CDN() == "true")
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
#else
<script src="/static/admin/plugins/jquery/3.2.1/jquery.min.js"></script>
#end

<!--[if lt IE 9]>
<script src="//cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
Expand Down

0 comments on commit 3a0b354

Please sign in to comment.