Skip to content

Commit 8e715df

Browse files
committed
Making CDN configurable from Site Admin.
1 parent 590c2bf commit 8e715df

File tree

4 files changed

+36
-48
lines changed

4 files changed

+36
-48
lines changed

source/DasBlog.Services/ConfigFile/SiteConfig.cs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,8 @@ public string Root {
7979
}
8080
}
8181
}
82-
83-
public string CdnFrom
84-
{
85-
get
86-
{
87-
return _cdnFrom;
88-
}
89-
set
90-
{
91-
if (!string.IsNullOrEmpty(value))
92-
{
93-
_cdnFrom = value + (value.EndsWith("/") ? "" : "/");
94-
}
95-
else
96-
{
97-
_cdnFrom = value;
98-
}
99-
}
100-
}
101-
102-
public string CdnTo
103-
{
104-
get
105-
{
106-
return _cdnTo;
107-
}
108-
set
109-
{
110-
if (!string.IsNullOrEmpty(value))
111-
{
112-
_cdnTo= value + (value.EndsWith("/") ? "" : "/");
113-
}
114-
else
115-
{
116-
_cdnTo = value;
117-
}
118-
}
119-
}
82+
public string CdnFrom { get; set; }
83+
public string CdnTo { get; set; }
12084

12185
public string AllowedHosts { get; set; }
12286
public string Copyright { get; set; }

source/DasBlog.Web.UI/Config/site.config

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929

3030
<!-- END OF SUGGESTED SETTINGS -->
3131

32-
<!-- OPTIONAL: Content Delivery Network (CDN)
33-
The two CDN settings below (CdnFrom/CdnTo) is a search and replace pattern.
34-
Note: This setting will not work from localhost when posting a new blog post.
35-
-->
36-
<!-- The part of your <Root> or binary hosting path you want to replace (ex. http://example.com/content/binary/): -->
37-
<CdnFrom></CdnFrom>
38-
<!-- The URL of the cdn servcie you are replacing to (ex. http://cdn.example.com/content/binary/): -->
39-
<CdnTo></CdnTo>
40-
4132
<MastodonServerUrl />
4233
<MastodonAccount />
4334

@@ -65,6 +56,16 @@
6556
<LogDir>logs</LogDir>
6657
<BinariesDir>content/binary</BinariesDir>
6758

59+
<!-- OPTIONAL: Content Delivery Network (CDN)
60+
The two CDN settings below (CdnFrom/CdnTo) is a search and replace pattern.
61+
* Default binaries storage is <Root>/<BinariesDir>.
62+
* Note: This setting will not work from localhost when posting a new blog post.
63+
-->
64+
<!-- The part of your <Root>/<BinariesDir> hosting path you want to replace (ex. http://example.com/content/binary/): -->
65+
<CdnFrom></CdnFrom>
66+
<!-- The URL of the cdn servcie you are replacing to (ex. http://cdn.example.com/content/binary/): -->
67+
<CdnTo></CdnTo>
68+
6869
<EnableTitlePermaLink>true</EnableTitlePermaLink>
6970
<EnableTitlePermaLinkUnique>false</EnableTitlePermaLinkUnique>
7071
<EnableTitlePermaLinkSpaces>false</EnableTitlePermaLinkSpaces>

source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,16 @@ public class SiteViewModel
240240

241241
[DisplayName("Time zone index")]
242242
[Description("")]
243-
244243
public int DisplayTimeZoneIndex { get; set; }
245244

245+
[DisplayName("CDN from")]
246+
[Description("The part of your Root URL to replace with the CDN URL. (optional)")]
247+
public string CdnFrom { get; set; }
248+
249+
[DisplayName("CDN to")]
250+
[Description("The CDN URL that will replace 'CDN from'. (optional)")]
251+
public string CdnTo { get; set; }
252+
246253
[DisplayName("Comments require approval")]
247254
[Description("")]
248255
public bool CommentsRequireApproval { get; set; }

source/DasBlog.Web.UI/Views/Admin/Settings.cshtml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,22 @@
694694
@Html.ValidationMessageFor(m => m.SiteConfig.DisplayTimeZoneIndex, null, new { @class = "text-danger" })
695695

696696
</div>
697+
698+
<div class="form-group row mb-3">
699+
700+
@Html.LabelFor(m => @Model.SiteConfig.CdnFrom, null, new { @class = "col-form-label col-sm-2" })
701+
<div class="col-sm-5">
702+
@Html.TextBoxFor(m => @Model.SiteConfig.CdnFrom, null, new { @class = "form-control sm-10" })
703+
</div>
704+
@Html.ValidationMessageFor(m => m.SiteConfig.CdnFrom, null, new { @class = "text-danger" })
705+
706+
@Html.LabelFor(m => @Model.SiteConfig.CdnTo, null, new { @class = "col-form-label col-sm-2" })
707+
<div class="col-sm-5">
708+
@Html.TextBoxFor(m => @Model.SiteConfig.CdnTo, null, new { @class = "form-control sm-10" })
709+
</div>
710+
@Html.ValidationMessageFor(m => m.SiteConfig.CdnTo, null, new { @class = "text-danger" })
711+
712+
</div>
697713

698714
<h3>Security</h3>
699715

0 commit comments

Comments
 (0)