Skip to content

Commit

Permalink
Making CDN configurable from Site Admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
noopman committed Jan 10, 2023
1 parent 590c2bf commit 8e715df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 48 deletions.
40 changes: 2 additions & 38 deletions source/DasBlog.Services/ConfigFile/SiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,8 @@ public string Root {
}
}
}

public string CdnFrom
{
get
{
return _cdnFrom;
}
set
{
if (!string.IsNullOrEmpty(value))
{
_cdnFrom = value + (value.EndsWith("/") ? "" : "/");
}
else
{
_cdnFrom = value;
}
}
}

public string CdnTo
{
get
{
return _cdnTo;
}
set
{
if (!string.IsNullOrEmpty(value))
{
_cdnTo= value + (value.EndsWith("/") ? "" : "/");
}
else
{
_cdnTo = value;
}
}
}
public string CdnFrom { get; set; }
public string CdnTo { get; set; }

public string AllowedHosts { get; set; }
public string Copyright { get; set; }
Expand Down
19 changes: 10 additions & 9 deletions source/DasBlog.Web.UI/Config/site.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@

<!-- END OF SUGGESTED SETTINGS -->

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

<MastodonServerUrl />
<MastodonAccount />

Expand Down Expand Up @@ -65,6 +56,16 @@
<LogDir>logs</LogDir>
<BinariesDir>content/binary</BinariesDir>

<!-- OPTIONAL: Content Delivery Network (CDN)
The two CDN settings below (CdnFrom/CdnTo) is a search and replace pattern.
* Default binaries storage is <Root>/<BinariesDir>.
* Note: This setting will not work from localhost when posting a new blog post.
-->
<!-- The part of your <Root>/<BinariesDir> hosting path you want to replace (ex. http://example.com/content/binary/): -->
<CdnFrom></CdnFrom>
<!-- The URL of the cdn servcie you are replacing to (ex. http://cdn.example.com/content/binary/): -->
<CdnTo></CdnTo>

<EnableTitlePermaLink>true</EnableTitlePermaLink>
<EnableTitlePermaLinkUnique>false</EnableTitlePermaLinkUnique>
<EnableTitlePermaLinkSpaces>false</EnableTitlePermaLinkSpaces>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,16 @@ public class SiteViewModel

[DisplayName("Time zone index")]
[Description("")]

public int DisplayTimeZoneIndex { get; set; }

[DisplayName("CDN from")]
[Description("The part of your Root URL to replace with the CDN URL. (optional)")]
public string CdnFrom { get; set; }

[DisplayName("CDN to")]
[Description("The CDN URL that will replace 'CDN from'. (optional)")]
public string CdnTo { get; set; }

[DisplayName("Comments require approval")]
[Description("")]
public bool CommentsRequireApproval { get; set; }
Expand Down
16 changes: 16 additions & 0 deletions source/DasBlog.Web.UI/Views/Admin/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,22 @@
@Html.ValidationMessageFor(m => m.SiteConfig.DisplayTimeZoneIndex, null, new { @class = "text-danger" })

</div>

<div class="form-group row mb-3">

@Html.LabelFor(m => @Model.SiteConfig.CdnFrom, null, new { @class = "col-form-label col-sm-2" })
<div class="col-sm-5">
@Html.TextBoxFor(m => @Model.SiteConfig.CdnFrom, null, new { @class = "form-control sm-10" })
</div>
@Html.ValidationMessageFor(m => m.SiteConfig.CdnFrom, null, new { @class = "text-danger" })

@Html.LabelFor(m => @Model.SiteConfig.CdnTo, null, new { @class = "col-form-label col-sm-2" })
<div class="col-sm-5">
@Html.TextBoxFor(m => @Model.SiteConfig.CdnTo, null, new { @class = "form-control sm-10" })
</div>
@Html.ValidationMessageFor(m => m.SiteConfig.CdnTo, null, new { @class = "text-danger" })

</div>

<h3>Security</h3>

Expand Down

0 comments on commit 8e715df

Please sign in to comment.