csharpfritz / csharpfritz/csharp_with_csharpfritz

Social share buttons for Blazor

Open
#110 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
664
Forks
209
PR merge metrics
No merged PRs in 30d

Description

Hi Jeff, thank you for your lessons and your answers!
**How to add social share buttons to Blazor**?
So far I've managed to get an active page address and sharing links.
Links are taken from: https://github.com/bradvin/social-share-urls

But I could only get `index.html` `title` and meta `description` tag contents by using JavaScript.
This is my separate Blazor component, Social.razor:
```
@inject NavigationManager UriManager
@inject IJSRuntime jsRuntime

LinkedIn
Facebook
Twitter
Pinterest
Skype
Line
QZone
Weibo
Reddit
LiveJournal
VK
OK
Telegram

@code {
public string Description = "";

public string Title = "";

protected override async Task OnInitializedAsync()
{
Title = await jsRuntime.InvokeAsync("getTitle");
Description = await jsRuntime.InvokeAsync("getDescription");
}
}
```
JavaScript to get an active page title, inserted into index.html
`window.getTitle = () => { return document.title; };`
JavaScript to get meta description contents, inserted into index.html:


window.getDescription = () => {
var metas = document.getElementsByTagName('meta');
for(var i in metas) {
if (typeof(metas[i].name) != 'undefined' && metas[i].name.toLowerCase() == "description") {
return encodeURIComponent(metas[i].content);
}
}
return '';
}

My question, _**how to get t:**_
- `PageTitle` from the active page
- description from `` inside `HeadContent`
- primary image url for the active page and image dimensions?

It looks like that it is possible without JavaScript

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.