Skip to content

Commit

Permalink
Merge pull request #207 from City-of-Helsinki/UHF-8102-job-search-met…
Browse files Browse the repository at this point in the history
…atags

UHF-8102: job search metatags
  • Loading branch information
Jussiles authored Mar 7, 2023
2 parents f795154 + a319e07 commit 7f53143
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.taxonomy_term.task_area.field_external_id
- field.field.taxonomy_term.task_area.field_metadata
- taxonomy.vocabulary.task_area
module:
- path
Expand All @@ -29,6 +30,14 @@ content:
size: 60
placeholder: ''
third_party_settings: { }
field_metadata:
type: string_textfield
weight: 102
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.taxonomy_term.task_area.field_external_id
- field.field.taxonomy_term.task_area.field_metadata
- taxonomy.vocabulary.task_area
module:
- text
Expand All @@ -27,6 +28,14 @@ content:
third_party_settings: { }
weight: 1
region: content
field_metadata:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 2
region: content
hidden:
langcode: true
search_api_excerpt: true
25 changes: 25 additions & 0 deletions conf/cmi/field.field.taxonomy_term.task_area.field_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uuid: 9dbe2125-8014-4501-9fd1-895c563bbe98
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_metadata
- taxonomy.vocabulary.task_area
module:
- disable_field
third_party_settings:
disable_field:
add_disable: none
edit_disable: none
id: taxonomy_term.task_area.field_metadata
field_name: field_metadata
entity_type: taxonomy_term
bundle: task_area
label: 'Meta data'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
21 changes: 21 additions & 0 deletions conf/cmi/field.storage.taxonomy_term.field_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: 0194c555-2084-46c4-8fdd-2254b17e294a
langcode: en
status: true
dependencies:
module:
- taxonomy
id: taxonomy_term.field_metadata
field_name: field_metadata
entity_type: taxonomy_term
type: string
settings:
max_length: 255
case_sensitive: false
is_ascii: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
36 changes: 27 additions & 9 deletions conf/cmi/search_api.index.job_listings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ langcode: en
status: true
dependencies:
config:
- field.storage.node.field_original_language
- field.storage.node.field_task_area
- field.storage.taxonomy_term.field_external_id
- field.storage.node.field_copied
- field.storage.node.field_employment_type
- field.storage.node.field_employment
- field.storage.taxonomy_term.field_search_id
- field.storage.node.field_employment_type
- field.storage.node.field_copied
- field.storage.node.field_job_duration
- field.storage.node.field_jobs
- field.storage.node.field_organization
- field.storage.node.field_publication_starts
- field.storage.node.field_organization_name
- field.storage.node.field_original_language
- field.storage.node.field_organization
- field.storage.node.field_jobs
- field.storage.node.field_postal_area
- field.storage.node.field_publication_starts
- field.storage.node.field_recruitment_id
- field.storage.node.field_recruitment_type
- field.storage.node.field_task_area
- search_api.server.elastic_rekry
module:
- taxonomy
- node
- scheduler
- search_api
- helfi_rekry_job_search
id: job_listings
name: 'Job listings'
description: ''
Expand Down Expand Up @@ -92,6 +92,14 @@ field_settings:
- field.storage.node.field_employment_type
module:
- taxonomy
field_external_id:
label: 'Ulkopuolinen ID'
datasource_id: 'entity:taxonomy_term'
property_path: field_external_id
type: integer
dependencies:
config:
- field.storage.taxonomy_term.field_external_id
field_job_duration:
label: 'Job duration'
datasource_id: 'entity:node'
Expand Down Expand Up @@ -208,6 +216,17 @@ field_settings:
dependencies:
module:
- node
task_area_external_id:
label: 'Ammattiala » Luokittelutermi » Ulkopuolinen ID'
datasource_id: 'entity:node'
property_path: 'field_task_area:entity:field_external_id'
type: integer
dependencies:
config:
- field.storage.node.field_task_area
- field.storage.taxonomy_term.field_external_id
module:
- taxonomy
task_area_id:
label: 'Ammattiala » Luokittelutermi » Termin ID'
datasource_id: 'entity:node'
Expand Down Expand Up @@ -289,7 +308,6 @@ processor_settings:
aggregated_field: { }
entity_status: { }
entity_type: { }
helfi_rekry_custom_labels: { }
ignorecase:
all_fields: false
fields:
Expand Down
93 changes: 91 additions & 2 deletions conf/cmi/simple_sitemap.custom_links.default.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,96 @@
_core:
default_config_hash: 25hWeYa4sasuJtHqKKcEN_nYiuEC1lMPYHsn5dawJEw
links:
-
path: /
priority: '1.0'
changefreq: daily
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=32&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=33&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=34&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=35&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=36&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=37&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=240&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=241&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=242&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=253&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=255&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=256&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=257&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=258&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=982&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=984&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=985&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=986&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=987&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=981&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=1097&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=1098&page=1'
priority: '1.0'
changefreq: ''
-
path: '/avoimet-tyopaikat/etsi-avoimia-tyopaikkoja?task_areas=1099&page=1'
priority: '1.0'

Large diffs are not rendered by default.

This file was deleted.

6 changes: 3 additions & 3 deletions public/modules/custom/helfi_rekry_job_search/assets/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,61 @@ declare(strict_types = 1);
function helfi_rekry_job_search_preprocess_paragraph__job_search(array &$variables) {
$variables['#attached']['library'][] = 'helfi_rekry_job_search/job-search';
}

/**
* Implements hook_page_attachments_alter().
*
* Update job search's task area pages metadata.
*/
function helfi_rekry_job_search_page_attachments_alter(array &$attachments) {
$queryParams = \Drupal::request()->query->all();

if (!array_key_exists('task_areas', $queryParams)) {
return;
}

// Only task_area and page paramaters allowed.
foreach ($queryParams as $queryParam => $queryParamValue) {
if ($queryParam !== 'task_areas' && $queryParam !== 'page') {
return;
}
}

// Only one task_area category allowed.
if (substr_count(\Drupal::request()->getRequestUri(), 'task_areas') > 1) {
return;
}

$currentUri = \Drupal::request()->getUri();
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();

foreach ($attachments['#attached']['html_head'] as $key => $head) {
switch ($head[1]) {
case 'canonical_url':
$attachments['#attached']['html_head'][$key][0]['#attributes']['href'] = $currentUri;
break;

case 'og_url':
case 'twitter_cards_page_url':
$attachments['#attached']['html_head'][$key][0]['#attributes']['content'] = $currentUri;
break;

case 'og_title':
case 'twitter_cards_title':
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties([
'vid' => 'task_area',
'field_external_id' => $queryParams['task_areas'],
]);

$term = reset($term);
if ($term->hasTranslation($langcode)) {
$term = $term->getTranslation($langcode);
}

if ($term->hasField('field_metadata') && !$term->get('field_metadata')->isEmpty()) {
$attachments['#attached']['html_head'][$key][0]['#attributes']['content'] = $term->get('field_metadata')->getString();
}
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const IndexFields = {
RECRUITMENT_TYPE: 'field_recruitment_type',
TASK_AREA: 'field_task_area',
TASK_AREA_ID: 'task_area_id',
TASK_AREA_EXTERNAL_ID: 'task_area_external_id',
LANGCODE: 'langcode',
SEARCH_ID: 'field_search_id',
STATUS: 'status',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const useQueryString = (urlParams: URLParams): string => {
if (urlParams?.task_areas?.length) {
must.push({
terms: {
[IndexFields.TASK_AREA_ID]: urlParams.task_areas,
[IndexFields.TASK_AREA_EXTERNAL_ID]: urlParams.task_areas,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const AGGREGATIONS = {
aggs: {
occupations: {
terms: {
field: 'task_area_id',
field: 'task_area_external_id',
size: 100,
},
},
Expand Down
4 changes: 2 additions & 2 deletions public/modules/custom/helfi_rekry_job_search/js/src/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ export const taskAreasAtom = atom<OptionType[]>((get) => {

return options
.map((option: Result<Term>) => {
const count = aggs.get(option._source.tid[0]) || 0;
const count = aggs.get(option._source.field_external_id[0]) || 0;
const name = option._source.name;

return {
count: count,
label: `${name} (${count})`,
simpleLabel: name,
value: option._source.tid[0],
value: option._source.field_external_id[0],
};
})
.sort((a: OptionType, b: OptionType) => sortOptions(a, b));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type Term = {
entity_type: string[];
name: string[];
tid: string[];
field_external_id: string[];
field_search_id?: string[];
url: string[];
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import SearchComponents from '../enum/SearchComponents';
import OptionType from './OptionType';

type URLParams = {
continuous?: boolean;
employment?: string[];
Expand Down

0 comments on commit 7f53143

Please sign in to comment.