SEO landing pages: dynamic role+city titles, pretty URLs, sitemap combos
CI/CD / CI · dotnet build (push) Successful in 4m5s
CI/CD / Deploy · hamkadr (push) Successful in 3m36s

Google Search Console shows all top queries are «استخدام [نقش] [شهر]», but the
filtered index pages all shared the generic title «موقعیت‌های استخدامی» and
weren't in the sitemap, so nothing ranked for those exact searches.

- Jobs/Shifts/Talent index pages now set a dynamic <title>/<h1>/meta from the
  active role+city (e.g. «استخدام پزشک عمومی در تهران»).
- Pretty SEO routes /استخدام/{role}/{city?} and /شیفت/{role}/{city?} (via
  AddPageRoute) resolve slugs → filters; unknown slug → 404. The layout already
  derives the canonical from the path, so each pretty URL is its own canonical
  and the query-string forms canonicalize to /Jobs (no duplicate content).
- sitemap.xml now lists role-only and role×city landing URLs for every combo
  with live listings (URL-encoded), so Google discovers them.
- New SeoSlug helper (Persian-tolerant: ي/ك, ZWNJ, hyphen/space).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-19 14:03:57 +03:30
parent 38031cb189
commit 0cf5b30dd8
8 changed files with 154 additions and 10 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
@page
@model JobsMedical.Web.Pages.Jobs.IndexModel
@{
ViewData["Title"] = "موقعیت‌های استخدامی";
// Title/description are set in the page model (SetSeo) from the active role/city.
}
<div class="page-head">
<div class="container">
<h1>موقعیت‌های استخدامی</h1>
<h1>@Model.PageHeading</h1>
<p class="muted">
@JalaliDate.ToPersianDigits(Model.Results.Count.ToString()) موقعیت شغلی پیدا شد
@if (Model.NearMeActive)
+41 -1
View File
@@ -20,6 +20,10 @@ public class IndexModel : PageModel
[BindProperty(SupportsGet = true)] public double? Lat { get; set; }
[BindProperty(SupportsGet = true)] public double? Lng { get; set; }
// Pretty-URL segments (/استخدام/{roleSlug}/{citySlug?}); resolved to RoleId/CityId below.
[BindProperty(SupportsGet = true)] public string? RoleSlug { get; set; }
[BindProperty(SupportsGet = true)] public string? CitySlug { get; set; }
public bool NearMeActive => Lat is not null && Lng is not null;
public List<JobOpening> Results { get; private set; } = new();
@@ -27,10 +31,29 @@ public class IndexModel : PageModel
public List<District> Districts { get; private set; } = new();
public List<Role> Roles { get; private set; } = new();
public async Task OnGetAsync()
/// <summary>Dynamic page heading/H1 + title, set from the active role/city for SEO.</summary>
public string PageHeading { get; private set; } = "موقعیت‌های استخدامی";
public async Task<IActionResult> OnGetAsync()
{
Cities = await _db.Cities.Where(c => c.IsActive).OrderBy(c => c.Name).ToListAsync();
Roles = await _db.Roles.Where(r => r.IsActive).OrderBy(r => r.SortOrder).ToListAsync();
// Pretty-URL landing: resolve slugs → filters. A slug matching nothing is a 404 (don't
// render a thin page under a junk URL).
if (!string.IsNullOrWhiteSpace(RoleSlug))
{
var role = Roles.FirstOrDefault(r => SeoSlug.Matches(r.Name, RoleSlug));
if (role is null) return NotFound();
RoleId = role.Id;
}
if (!string.IsNullOrWhiteSpace(CitySlug))
{
var city = Cities.FirstOrDefault(c => SeoSlug.Matches(c.Name, CitySlug));
if (city is null) return NotFound();
CityId = city.Id;
}
Districts = await _db.Districts
.Where(d => d.IsActive && (CityId == null || d.CityId == CityId))
.OrderBy(d => d.Name).ToListAsync();
@@ -63,5 +86,22 @@ public class IndexModel : PageModel
{
Results = results.OrderByDescending(j => j.CreatedAt).ToList();
}
SetSeo(Roles.FirstOrDefault(r => r.Id == RoleId)?.Name, Cities.FirstOrDefault(c => c.Id == CityId)?.Name);
return Page();
}
/// <summary>Title/H1/meta from the active role+city so the page targets «استخدام [نقش] [شهر]».</summary>
private void SetSeo(string? role, string? city)
{
PageHeading =
role is not null && city is not null ? $"استخدام {role} در {city}"
: role is not null ? $"استخدام {role}"
: city is not null ? $"استخدام کادر درمان در {city}"
: "موقعیت‌های استخدامی";
ViewData["Title"] = PageHeading;
ViewData["Description"] = role is not null || city is not null
? $"جدیدترین آگهی‌های {PageHeading} در همکادر؛ مشاهده فرصت‌ها و تماس مستقیم با مراکز درمانی."
: "موقعیت‌های استخدامی کادر درمان (پزشک، پرستار، ماما، تکنسین) در بیمارستان‌ها و کلینیک‌های تهران — همکادر.";
}
}
@@ -1,12 +1,12 @@
@page
@model JobsMedical.Web.Pages.Shifts.IndexModel
@{
ViewData["Title"] = "شیفت‌های موجود";
// Title/description are set in the page model (SetSeo) from the active role/city.
}
<div class="page-head">
<div class="container">
<h1>شیفت‌های موجود</h1>
<h1>@Model.PageHeading</h1>
<p class="muted">
@JalaliDate.ToPersianDigits(Model.Results.Count.ToString()) شیفت باز پیدا شد
@if (Model.NearMeActive)
@@ -25,6 +25,10 @@ public class IndexModel : PageModel
[BindProperty(SupportsGet = true)] public double? Lat { get; set; }
[BindProperty(SupportsGet = true)] public double? Lng { get; set; }
// Pretty-URL segments (/شیفت/{roleSlug}/{citySlug?}); resolved to RoleId/CityId below.
[BindProperty(SupportsGet = true)] public string? RoleSlug { get; set; }
[BindProperty(SupportsGet = true)] public string? CitySlug { get; set; }
public bool NearMeActive => Lat is not null && Lng is not null;
public List<Shift> Results { get; private set; } = new();
@@ -33,12 +37,30 @@ public class IndexModel : PageModel
public List<Role> Roles { get; private set; } = new();
public List<Facility> Facilities { get; private set; } = new();
public async Task OnGetAsync()
/// <summary>Dynamic page heading/H1 + title, set from the active role/city for SEO.</summary>
public string PageHeading { get; private set; } = "شیفت‌های خالی";
public async Task<IActionResult> OnGetAsync()
{
var today = DateOnly.FromDateTime(DateTime.UtcNow);
Cities = await _db.Cities.Where(c => c.IsActive).OrderBy(c => c.Name).ToListAsync();
Roles = await _db.Roles.Where(r => r.IsActive).OrderBy(r => r.SortOrder).ToListAsync();
// Pretty-URL landing: resolve slugs → filters (404 on a slug that matches nothing).
if (!string.IsNullOrWhiteSpace(RoleSlug))
{
var role = Roles.FirstOrDefault(r => SeoSlug.Matches(r.Name, RoleSlug));
if (role is null) return NotFound();
RoleId = role.Id;
}
if (!string.IsNullOrWhiteSpace(CitySlug))
{
var city = Cities.FirstOrDefault(c => SeoSlug.Matches(c.Name, CitySlug));
if (city is null) return NotFound();
CityId = city.Id;
}
Districts = await _db.Districts
.Where(d => d.IsActive && (CityId == null || d.CityId == CityId))
.OrderBy(d => d.Name).ToListAsync();
@@ -82,5 +104,22 @@ public class IndexModel : PageModel
{
Results = results.OrderBy(s => s.Date).ThenBy(s => s.StartTime).ToList();
}
SetSeo(Roles.FirstOrDefault(r => r.Id == RoleId)?.Name, Cities.FirstOrDefault(c => c.Id == CityId)?.Name);
return Page();
}
/// <summary>Title/H1/meta from the active role+city so the page targets «شیفت [نقش] [شهر]».</summary>
private void SetSeo(string? role, string? city)
{
PageHeading =
role is not null && city is not null ? $"شیفت {role} در {city}"
: role is not null ? $"شیفت {role}"
: city is not null ? $"شیفت کادر درمان در {city}"
: "شیفت‌های خالی";
ViewData["Title"] = PageHeading;
ViewData["Description"] = role is not null || city is not null
? $"جدیدترین {PageHeading} در همکادر؛ مشاهده شیفت‌ها و تماس مستقیم با مراکز درمانی."
: "شیفت‌های خالی کادر درمان (پزشک، پرستار، ماما، تکنسین) در بیمارستان‌ها و کلینیک‌های تهران — همکادر.";
}
}
@@ -1,14 +1,13 @@
@page
@model JobsMedical.Web.Pages.Talent.IndexModel
@{
ViewData["Title"] = "آماده به کار — کادر درمان";
ViewData["Description"] = "فهرست کادر درمان آماده همکاری (پزشک، پرستار، ماما، تکنسین و…) در تهران و سایر شهرها — مرکز درمانی می‌تواند مستقیم تماس بگیرد.";
// Title/description are set in the page model (from the active role/city).
ViewData["q"] = Model.Q; // drives result highlighting in cards
}
<div class="page-head">
<div class="container">
<h1>آماده به کار</h1>
<h1>@Model.PageHeading</h1>
<p class="muted">
@JalaliDate.ToPersianDigits(Model.Results.Count.ToString()) نیروی کادر درمان آماده‌ی همکاری —
مراکز درمانی می‌توانند مستقیم تماس بگیرند.
@@ -23,6 +23,9 @@ public class IndexModel : PageModel
public List<District> Districts { get; private set; } = new();
public List<Role> Roles { get; private set; } = new();
/// <summary>Dynamic page heading/H1 + title, set from the active role/city for SEO.</summary>
public string PageHeading { get; private set; } = "کادر درمان آماده به کار";
public async Task OnGetAsync()
{
Cities = await _db.Cities.Where(c => c.IsActive).OrderBy(c => c.Name).ToListAsync();
@@ -58,5 +61,15 @@ public class IndexModel : PageModel
}
Results = await q.OrderByDescending(t => t.CreatedAt).ToListAsync();
var role = Roles.FirstOrDefault(r => r.Id == RoleId)?.Name;
var city = Cities.FirstOrDefault(c => c.Id == CityId)?.Name;
PageHeading =
role is not null && city is not null ? $"{role} آماده به کار در {city}"
: role is not null ? $"{role} آماده به کار"
: city is not null ? $"کادر درمان آماده به کار در {city}"
: "کادر درمان آماده به کار";
ViewData["Title"] = PageHeading;
ViewData["Description"] = $"فهرست «آماده به کار» {(role ?? "کادر درمان")}{(city is not null ? " در " + city : "")} — همکادر؛ مشاهده و تماس مستقیم.";
}
}