Fix useless bare-divar.ir links + hide empty homepage shifts section
- Divar listings with no extractable post token were given SourceUrl «https://divar.ir» — a link that just opens Divar''s homepage, not the ad. Store null instead, and guard the contact-modal fallback to require a real path (so existing bare-domain links stop being offered too). - Homepage «جدیدترین شیفتها»: only render when there are real open shifts. Almost all aggregated ads are ongoing hiring (jobs), not dated shifts, so the section was showing a fabricated shift date (the «۱۸ خرداد» on the welcome page). Now it hides when empty. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -53,27 +53,25 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
@* Shifts are rare for aggregated content (most ads are ongoing hiring, not dated shifts) — only
|
||||
show the section when there are real open shifts, so we never display a fabricated/empty date. *@
|
||||
@if (Model.LatestShifts.Count > 0)
|
||||
{
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="section-head">
|
||||
<h2>جدیدترین شیفتها</h2>
|
||||
<a href="/Shifts">مشاهده همه ←</a>
|
||||
</div>
|
||||
@if (Model.LatestShifts.Count == 0)
|
||||
{
|
||||
<div class="empty-state">فعلاً شیفت بازی ثبت نشده است.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="grid grid-3">
|
||||
@foreach (var s in Model.LatestShifts)
|
||||
{
|
||||
<partial name="_ShiftCard" model="s" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
}
|
||||
|
||||
@if (Model.LatestJobs.Count > 0)
|
||||
{
|
||||
|
||||
@@ -426,7 +426,7 @@ app.MapGet("/contact", async (string? type, int id, AppDbContext db, InterestSer
|
||||
if (!string.IsNullOrWhiteSpace(s.Facility!.BaleId)) items.Add(Item(ContactType.Bale, s.Facility.BaleId!));
|
||||
}
|
||||
if (items.Count == 0 && !string.IsNullOrWhiteSpace(s.SourceUrl)
|
||||
&& Uri.TryCreate(s.SourceUrl, UriKind.Absolute, out var ss))
|
||||
&& Uri.TryCreate(s.SourceUrl, UriKind.Absolute, out var ss) && ss.AbsolutePath.Trim('/').Length > 0)
|
||||
{ fallbackUrl = s.SourceUrl; fallbackLabel = ss.Host.Contains("divar") ? "مشاهده شماره در دیوار ↗" : "مشاهده آگهی در منبع ↗"; }
|
||||
await interest.LogAsync(InterestEventType.Apply, id);
|
||||
break;
|
||||
@@ -444,7 +444,7 @@ app.MapGet("/contact", async (string? type, int id, AppDbContext db, InterestSer
|
||||
if (!string.IsNullOrWhiteSpace(j.Facility!.BaleId)) items.Add(Item(ContactType.Bale, j.Facility.BaleId!));
|
||||
}
|
||||
if (items.Count == 0 && !string.IsNullOrWhiteSpace(j.SourceUrl)
|
||||
&& Uri.TryCreate(j.SourceUrl, UriKind.Absolute, out var js))
|
||||
&& Uri.TryCreate(j.SourceUrl, UriKind.Absolute, out var js) && js.AbsolutePath.Trim('/').Length > 0)
|
||||
{ fallbackUrl = j.SourceUrl; fallbackLabel = js.Host.Contains("divar") ? "مشاهده شماره در دیوار ↗" : "مشاهده آگهی در منبع ↗"; }
|
||||
await interest.LogJobAsync(InterestEventType.Apply, id);
|
||||
break;
|
||||
@@ -458,7 +458,7 @@ app.MapGet("/contact", async (string? type, int id, AppDbContext db, InterestSer
|
||||
items.AddRange(t.Contacts.OrderBy(c => c.SortOrder).Select(c => Item(c.Type, c.Value)));
|
||||
if (items.Count == 0 && !string.IsNullOrWhiteSpace(t.Phone)) items.Add(Item(ContactType.Mobile, t.Phone!));
|
||||
if (items.Count == 0 && !string.IsNullOrWhiteSpace(t.SourceUrl)
|
||||
&& Uri.TryCreate(t.SourceUrl, UriKind.Absolute, out var su))
|
||||
&& Uri.TryCreate(t.SourceUrl, UriKind.Absolute, out var su) && su.AbsolutePath.Trim('/').Length > 0)
|
||||
{ fallbackUrl = t.SourceUrl; fallbackLabel = su.Host.Contains("divar") ? "مشاهده شماره در دیوار ↗" : "مشاهده آگهی در منبع ↗"; }
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,9 @@ public class DivarListingSource : IListingSource
|
||||
var cityLabel = CityLabel(s.DivarCity); // every result is from the city we searched
|
||||
foreach (var (text, token) in Harvest(doc.RootElement).Take(25))
|
||||
{
|
||||
var url = token is not null ? $"https://divar.ir/v/{token}" : "https://divar.ir";
|
||||
// Only a real post token gives a usable deep link. Without one, leave SourceUrl null —
|
||||
// a bare «https://divar.ir» just opens Divar's homepage, which is useless to the user.
|
||||
var url = token is not null ? $"https://divar.ir/v/{token}" : null;
|
||||
var itemText = text;
|
||||
// Stamp the city so the parser/AI always resolve a location (Divar's own location
|
||||
// line isn't always in the search row; the searched city is authoritative).
|
||||
|
||||
Reference in New Issue
Block a user