diff --git a/seo_helpers.py b/seo_helpers.py index 278d171..7e78926 100644 --- a/seo_helpers.py +++ b/seo_helpers.py @@ -177,144 +177,71 @@ def generate_vacancy_seo_tags(vacancy_data: Dict[str, Any], vacancy_id: int) -> def inject_seo_tags(html_template: str, seo_tags: Dict[str, str]) -> str: """ Внедрение SEO-тегов в HTML шаблон - - Args: - html_template: исходный HTML - seo_tags: словарь с SEO-тегами - - Returns: - HTML с замененными SEO-тегами """ - replacements = { - 'Резюме | Rabota.Today': f'{seo_tags.get("title", "Rabota.Today")}', - 'Вакансия | Rabota.Today': f'{seo_tags.get("title", "Rabota.Today")}', - '{seo_tags.get("title", "Rabota.Today")}', result) - # Вставляем конкретные значения - if 'description' in seo_tags: - desc_pattern = '', desc_start) - if desc_end != -1: - result = result[ - :desc_start] + f'' + result[ - desc_end + 2:] + # Заменяем description + desc_pattern = '' + result = re.sub(desc_pattern, f'', result) - if 'keywords' in seo_tags: - keywords_pattern = '', keywords_start) - if keywords_end != -1: - result = result[:keywords_start] + f'' + result[ - keywords_end + 2:] + # Заменяем keywords + keywords_pattern = '' + result = re.sub(keywords_pattern, f'', result) - if 'og_title' in seo_tags: - og_title_pattern = '', og_title_start) - if og_title_end != -1: - result = result[ - :og_title_start] + f'' + result[ - og_title_end + 2:] + # Заменяем og:title + og_title_pattern = '' + result = re.sub(og_title_pattern, f'', result) - if 'og_description' in seo_tags: - og_desc_pattern = '', og_desc_start) - if og_desc_end != -1: - result = result[ - :og_desc_start] + f'' + result[ - og_desc_end + 2:] + # Заменяем og:description + og_desc_pattern = '' + result = re.sub(og_desc_pattern, f'', + result) - if 'og_url' in seo_tags: - og_url_pattern = '', og_url_start) - if og_url_end != -1: - result = result[:og_url_start] + f'' + result[ - og_url_end + 2:] + # Заменяем og:url + og_url_pattern = '' + result = re.sub(og_url_pattern, f'', result) + # Заменяем profile:first_name + first_name_pattern = '' if 'profile_first_name' in seo_tags: - first_name_pattern = '', first_name_start) - if first_name_end != -1: - result = result[ - :first_name_start] + f'' + result[ - first_name_end + 2:] + result = re.sub(first_name_pattern, + f'', + result) + # Заменяем profile:last_name + last_name_pattern = '' if 'profile_last_name' in seo_tags: - last_name_pattern = '', last_name_start) - if last_name_end != -1: - result = result[ - :last_name_start] + f'' + result[ - last_name_end + 2:] + result = re.sub(last_name_pattern, + f'', + result) - if 'twitter_title' in seo_tags: - twitter_title_pattern = '', twitter_title_start) - if twitter_title_end != -1: - result = result[ - :twitter_title_start] + f'' + result[ - twitter_title_end + 2:] + # Заменяем twitter:title + twitter_title_pattern = '' + result = re.sub(twitter_title_pattern, f'', + result) - if 'twitter_description' in seo_tags: - twitter_desc_pattern = '', twitter_desc_start) - if twitter_desc_end != -1: - result = result[ - :twitter_desc_start] + f'' + result[ - twitter_desc_end + 2:] + # Заменяем twitter:description + twitter_desc_pattern = '' + result = re.sub(twitter_desc_pattern, + f'', result) - if 'canonical_url' in seo_tags: - canonical_pattern = '', canonical_start) - if canonical_end != -1: - result = result[ - :canonical_start] + f'' + result[ - canonical_end + 2:] + # Заменяем canonical + canonical_pattern = '' + result = re.sub(canonical_pattern, f'', result) - # Вставляем структурированные данные - if 'structured_data' in seo_tags: - structured_pattern = '', structured_start) - if structured_end != -1: - result = result[ - :structured_start] + f'\n + structured_pattern = r'' + # Находим и заменяем первый блок структурированных данных + result = re.sub(structured_pattern, + f'', result, + count=1) + + # Удаляем второй пустой блок, если он есть + empty_structured_pattern = r'' + result = re.sub(empty_structured_pattern, '', result) return result \ No newline at end of file diff --git a/templates/vacancy_detail.html b/templates/vacancy_detail.html index abbda72..18e94e4 100644 --- a/templates/vacancy_detail.html +++ b/templates/vacancy_detail.html @@ -34,7 +34,7 @@ -