Skip to content

Commit

Permalink
Merge pull request #37 from libanlsilva/Fix-TitleLink
Browse files Browse the repository at this point in the history
Update HubspotRepository.cs
  • Loading branch information
WillStrohl authored May 9, 2024
2 parents 420bef2 + d2307ea commit 4512cfd
Showing 1 changed file with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ DEALINGS IN THE SOFTWARE.
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Instrumentation;
using DotNetNuke.Services.Localization;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.Hosting;
using UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.Constants;
using UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.Data;
using UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.Models;
using UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.Repository.Contract;
using UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.ViewModels;
using System.Linq;
using DotNetNuke.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Hosting;
using System.Security.Policy;
using System.Text.RegularExpressions;
using DotNetNuke.Services.Localization;
using System.Web;

namespace UpendoVentures.Modules.HubSpotEasyDnnNewsBlogMigrator.Repository
{
Expand Down Expand Up @@ -230,6 +227,33 @@ public HubspotRepository(DapperContext context, IEasyDNNNewsRepository easyDNNNe
}
}

/// <summary>
/// Get title link from Hubspot Article Url.
/// </summary>
/// <param name="url">Hubspot Article Url</param>
/// <returns>New Title Link.</returns>
private string GetTitleLink(string url)
{
try
{
Uri uri = new Uri(url);
string absolutePath = uri.AbsolutePath;
absolutePath = absolutePath.TrimEnd('/');
string[] parts = absolutePath.Split('/');
string desiredText = parts[parts.Length - 1];

if (string.IsNullOrEmpty(desiredText))
return string.Empty;

return desiredText;
}
catch (Exception)
{

return string.Empty;
}
}

/// <summary>
/// Migrates the blog posts from Hubspot.
/// </summary>
Expand Down Expand Up @@ -307,7 +331,7 @@ public async Task<int> MigratePosts(string accessToken)
NumberOfViews = 0,
RatingValue = 0,
RatingCount = 0,
TitleLink = string.IsNullOrEmpty(item.HtmlTitle) ? string.Empty : ReplaceAndRemove(item.HtmlTitle),
TitleLink = string.IsNullOrEmpty(item.Url) ? (string.IsNullOrEmpty(item.HtmlTitle) ? string.Empty : ReplaceAndRemove(item.HtmlTitle)) : GetTitleLink(item.Url),
DetailType = Constant.BlogData.DetailType,
DetailsTemplate = Constant.BlogData.DetailsTemplate,
DetailsTheme = Constant.BlogData.DetailsTemplate,
Expand Down

0 comments on commit 4512cfd

Please sign in to comment.