Skip to content

Commit

Permalink
Added social sharing buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
madskristensen committed Sep 11, 2017
1 parent 64f562c commit 02cb47f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A photo gallery site implemented in ASP.NET Core 2.0 Razor Pages.
- Elegant masonry layout of images
- Easy to manage through simple [admin interface](#admin-interface)
- All major browsers fully supported (IE 10+)
- Social media integration (Facebook, Twitter, Pinterest)
- Follows best practices for web applications
- [See DareBoost report](art/dareboost-report.pdf)

Expand Down
13 changes: 7 additions & 6 deletions src/Pages/Album.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,22 @@ public async Task<IActionResult> OnPostUpload(string name, ICollection<IFormFile

foreach (var file in files.Where(f => _ac.IsImageFile(f.FileName)))
{
string path = Path.Combine(_environment.WebRootPath, "albums", album.Name, Path.GetFileName(file.FileName));
string fileName = Path.GetFileName(file.FileName);
string filePath = Path.Combine(_environment.WebRootPath, "albums", album.Name, Path.GetFileName(fileName));

if (System.IO.File.Exists(path))
if (System.IO.File.Exists(filePath))
{
path = Path.ChangeExtension(path, file.GetHashCode() + Path.GetExtension(path));
filePath = Path.ChangeExtension(filePath, file.GetHashCode() + Path.GetExtension(filePath));
}

using (var imageStream = file.OpenReadStream())
using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
_processor.CreateThumbnails(imageStream, path);
_processor.CreateThumbnails(imageStream, filePath);
await file.CopyToAsync(fileStream);
}

var photo = new Photo(album, new FileInfo(path));
var photo = new Photo(album, new FileInfo(filePath));
album.Photos.Insert(0, photo);
}

Expand Down
1 change: 1 addition & 0 deletions src/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<main class="container">
@RenderBody()
@{await Html.RenderPartialAsync("_SocialButtons.cshtml", ViewData["Title"]);}
</main>

<footer>
Expand Down
24 changes: 24 additions & 0 deletions src/Pages/_SocialButtons.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@model string
@{
string currentUrl = Context.Request.Scheme + "://" + Context.Request.Host + Context.Request.Path;
string enc = System.Net.WebUtility.UrlEncode(currentUrl);
string text = System.Net.WebUtility.UrlEncode(Model);
}

<ul class="share-buttons">
<li>
<a href="https://twitter.com/intent/tweet?source=@enc&text=@text" target="_blank" title="Tweet" rel="noreferrer noopener">
<img alt="Tweet" src="~/img/twitter.png" width="32" height="32" />
</a>
</li>
<li>
<a href="http://pinterest.com/pin/create/button/?url=@enc&description=@text" target="_blank" title="Pin it" rel="noreferrer noopener">
<img alt="Pin it" src="~/img/pinterest.png" width="32" height="32" />
</a>
</li>
<li>
<a href="https://www.facebook.com/sharer/sharer.php?u=@enc" title="Share on Facebook" target="_blank" rel="noreferrer noopener">
<img alt="Share on Facebook" src="~/img/facebook.png" width="32" height="32" />
</a>
</li>
</ul>
1 change: 0 additions & 1 deletion src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down
10 changes: 10 additions & 0 deletions src/wwwroot/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ a {
}
}

.share-buttons {
list-style: none;
padding: 0;

li {
display: inline-block;
margin-right: .3em;
}
}

footer {
position: absolute;
bottom: 0;
Expand Down
Binary file added src/wwwroot/img/facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/wwwroot/img/pinterest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/wwwroot/img/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 02cb47f

Please sign in to comment.