feat: AcfSocial / parseAcfSocial
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"key": "group_abstract_social",
|
||||
"title": "Abstract - Social",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_6855a1d643408",
|
||||
"label": "Médias sociaux",
|
||||
"name": "profiles",
|
||||
"aria-label": "",
|
||||
"type": "repeater",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"acfe_repeater_stylised_button": 0,
|
||||
"layout": "table",
|
||||
"pagination": 0,
|
||||
"min": 0,
|
||||
"max": 0,
|
||||
"collapsed": "",
|
||||
"button_label": "Ajouter un élément",
|
||||
"show_in_graphql": 1,
|
||||
"graphql_description": "",
|
||||
"graphql_field_name": "profiles",
|
||||
"graphql_non_null": 1,
|
||||
"rows_per_page": 20,
|
||||
"sub_fields": [
|
||||
{
|
||||
"key": "field_6855a7e143409",
|
||||
"label": "URL",
|
||||
"name": "url",
|
||||
"aria-label": "",
|
||||
"type": "url",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"allow_in_bindings": 0,
|
||||
"placeholder": "",
|
||||
"show_in_graphql": 1,
|
||||
"graphql_description": "",
|
||||
"graphql_field_name": "url",
|
||||
"graphql_non_null": 1,
|
||||
"parent_repeater": "field_6855a1d643408"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "abstract"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": true,
|
||||
"description": "",
|
||||
"show_in_rest": 0,
|
||||
"display_title": "",
|
||||
"acfe_autosync": [
|
||||
"json"
|
||||
],
|
||||
"acfe_form": 0,
|
||||
"show_in_graphql": 1,
|
||||
"graphql_field_name": "GroupAbstractSocial",
|
||||
"map_graphql_types_from_location_rules": 0,
|
||||
"graphql_types": "",
|
||||
"acfe_meta": "",
|
||||
"acfe_note": "",
|
||||
"modified": 1769788591
|
||||
}
|
||||
@@ -48,6 +48,34 @@
|
||||
"graphql_field_name": "phoneNumber",
|
||||
"graphql_non_null": 1
|
||||
},
|
||||
{
|
||||
"key": "field_697cd4c5fc56a",
|
||||
"label": "Médias sociaux",
|
||||
"name": "social",
|
||||
"aria-label": "",
|
||||
"type": "clone",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"graphql_field_name": "social",
|
||||
"clone": [
|
||||
"group_abstract_social"
|
||||
],
|
||||
"display": "seamless",
|
||||
"layout": "block",
|
||||
"prefix_label": 0,
|
||||
"prefix_name": 0,
|
||||
"acfe_seamless_style": 0,
|
||||
"acfe_clone_modal": 0,
|
||||
"acfe_clone_modal_close": 0,
|
||||
"acfe_clone_modal_button": "",
|
||||
"acfe_clone_modal_size": "large"
|
||||
},
|
||||
{
|
||||
"key": "field_697cc921234cc",
|
||||
"label": "Liens globaux",
|
||||
@@ -126,5 +154,5 @@
|
||||
"graphql_types": "",
|
||||
"acfe_meta": "",
|
||||
"acfe_note": "",
|
||||
"modified": 1769785750
|
||||
"modified": 1769788698
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fragment AcfSocial on GroupAbstractSocial_Fields {
|
||||
profiles {
|
||||
url
|
||||
}
|
||||
}
|
||||
11
wp-content/themes/moonshine/app/components/acf/AcfSocial.vue
Normal file
11
wp-content/themes/moonshine/app/components/acf/AcfSocial.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{ social?: AcfSocialOutput }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="social?.profiles" class="flex gap-1.5">
|
||||
<a v-for="({ url, icon }, key) in social.profiles" :key="key" :href="url" target="_blank" rel="noopener noreferrer" class="flex">
|
||||
<UIcon :name="icon" />
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,13 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
const { data: siteOptions } = await useSiteOptions();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UFooter id="site-footer">
|
||||
<template #left>
|
||||
<SiteFooterCopyright />
|
||||
</template>
|
||||
<template #right>
|
||||
<SiteFooterCredits />
|
||||
</template>
|
||||
</UFooter>
|
||||
<footer class="bg-accented links:link-prose">
|
||||
<div class="container py-6">
|
||||
<AcfSocialProfiles :social="parseAcfSocial(siteOptions)" />
|
||||
</div>
|
||||
<SiteFooterBottom />
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<div class="bg-inverted text-inverted py-1.5">
|
||||
<div class="container flex flex-col sm:flex-row items-center gap-3">
|
||||
<SiteFooterCopyright class="sm:mr-auto" />
|
||||
<AuthConnexionButton color="neutral" variant="link" />
|
||||
<SiteFooterCredits />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,6 +1,7 @@
|
||||
fragment SiteOptions on GroupSiteOptions {
|
||||
email
|
||||
phoneNumber { ... AcfPhone }
|
||||
...AcfSocial
|
||||
links {
|
||||
contact { ... AcfLink}
|
||||
}
|
||||
|
||||
32
wp-content/themes/moonshine/app/utils/acf-social.ts
Normal file
32
wp-content/themes/moonshine/app/utils/acf-social.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as z from "zod";
|
||||
import type { AcfSocialFragment } from "#graphql/operations";
|
||||
|
||||
const socialProfile = z.object({ url: z.url() }).transform(({ url }) => ({ url, icon: getSocialIcon(url) }));
|
||||
const acfSocialSchema = z.object({
|
||||
profiles: z.array(socialProfile),
|
||||
});
|
||||
export type AcfSocialOutput = z.infer<typeof acfSocialSchema>;
|
||||
|
||||
export function parseAcfSocial(data?: AcfSocialFragment) {
|
||||
try {
|
||||
return acfSocialSchema.parse(data);
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const socialIconMap = {
|
||||
"facebook.com": "i-cib-facebook-f",
|
||||
"twitter.com": "i-cib-twitter",
|
||||
"x.com": "i-cib-twitter",
|
||||
"instagram.com": "i-cib-instagram",
|
||||
"youtube.com": "i-cib-youtube",
|
||||
"linkedin.com": "i-cib-linkedin",
|
||||
"tiktok.com": "i-cib-tiktok",
|
||||
};
|
||||
|
||||
function getSocialIcon(url: string): string {
|
||||
const domain = new URL(url).hostname.toLowerCase().replace(/^www\./, "");
|
||||
return socialIconMap[domain as keyof typeof socialIconMap] ?? "i-lucide-globe";
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
const socialIconMap = {
|
||||
"facebook.com": "i-cib-facebook-f",
|
||||
"twitter.com": "i-cib-twitter",
|
||||
"x.com": "i-cib-twitter",
|
||||
"instagram.com": "i-cib-instagram",
|
||||
"youtube.com": "i-cib-youtube",
|
||||
"linkedin.com": "i-cib-linkedin",
|
||||
"tiktok.com": "i-cib-tiktok",
|
||||
};
|
||||
|
||||
export function mapSocialIcon(url: string) {
|
||||
try {
|
||||
const domain = new URL(url).hostname.toLowerCase().replace(/^www\./, "");
|
||||
const icon = socialIconMap[domain as keyof typeof socialIconMap];
|
||||
if (!icon) throw new Error(`Média social introuvable ${url}`);
|
||||
return icon;
|
||||
}
|
||||
catch {
|
||||
return "i-lucide-globe";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
// Override TermConnection query args
|
||||
// Override term connection query args
|
||||
add_filter( 'graphql_term_object_connection_query_args', 'moonshine_graphql_term_object_connection_query_args', 10, 3 );
|
||||
function moonshine_graphql_term_object_connection_query_args( $query_args, $source, $args ) {
|
||||
// Sort by 'order' meta value instead of legacy 'term_order' field
|
||||
|
||||
@@ -3639,6 +3639,58 @@ interface GroupAbstractMedia_Fields implements AcfFieldGroup & AcfFieldGroupFiel
|
||||
objectFit: String!
|
||||
}
|
||||
|
||||
"""
|
||||
The "GroupAbstractSocial" Field Group. Added to the Schema by "WPGraphQL for ACF".
|
||||
"""
|
||||
type GroupAbstractSocial implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractSocial_Fields {
|
||||
"""The name of the field group"""
|
||||
fieldGroupName: String @deprecated(reason: "Use __typename instead")
|
||||
|
||||
"""
|
||||
Field of the "repeater" Field Type added to the schema as part of the "GroupAbstractSocial" Field Group
|
||||
"""
|
||||
profiles: [GroupAbstractSocialProfiles]!
|
||||
}
|
||||
|
||||
"""
|
||||
The "GroupAbstractSocialProfiles" Field Group. Added to the Schema by "WPGraphQL for ACF".
|
||||
"""
|
||||
type GroupAbstractSocialProfiles implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractSocialProfiles_Fields {
|
||||
"""The name of the field group"""
|
||||
fieldGroupName: String @deprecated(reason: "Use __typename instead")
|
||||
|
||||
"""
|
||||
Field of the "url" Field Type added to the schema as part of the "GroupAbstractSocialProfiles" Field Group
|
||||
"""
|
||||
url: String!
|
||||
}
|
||||
|
||||
"""
|
||||
Interface representing fields of the ACF "GroupAbstractSocialProfiles" Field Group
|
||||
"""
|
||||
interface GroupAbstractSocialProfiles_Fields implements AcfFieldGroup & AcfFieldGroupFields {
|
||||
"""The name of the field group"""
|
||||
fieldGroupName: String @deprecated(reason: "Use __typename instead")
|
||||
|
||||
"""
|
||||
Field of the "url" Field Type added to the schema as part of the "GroupAbstractSocialProfiles" Field Group
|
||||
"""
|
||||
url: String!
|
||||
}
|
||||
|
||||
"""
|
||||
Interface representing fields of the ACF "GroupAbstractSocial" Field Group
|
||||
"""
|
||||
interface GroupAbstractSocial_Fields implements AcfFieldGroup & AcfFieldGroupFields {
|
||||
"""The name of the field group"""
|
||||
fieldGroupName: String @deprecated(reason: "Use __typename instead")
|
||||
|
||||
"""
|
||||
Field of the "repeater" Field Type added to the schema as part of the "GroupAbstractSocial" Field Group
|
||||
"""
|
||||
profiles: [GroupAbstractSocialProfiles]!
|
||||
}
|
||||
|
||||
"""
|
||||
The "GroupLayoutContained" Field Group. Added to the Schema by "WPGraphQL for ACF".
|
||||
"""
|
||||
@@ -3714,7 +3766,7 @@ interface GroupPostPage_Fields implements AcfFieldGroup & AcfFieldGroupFields &
|
||||
"""
|
||||
The "GroupSiteOptions" Field Group. Added to the Schema by "WPGraphQL for ACF".
|
||||
"""
|
||||
type GroupSiteOptions implements AcfFieldGroup & AcfFieldGroupFields & GroupSiteOptions_Fields {
|
||||
type GroupSiteOptions implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractSocial_Fields & GroupSiteOptions_Fields {
|
||||
"""
|
||||
Field of the "email" Field Type added to the schema as part of the "GroupSiteOptions" Field Group
|
||||
"""
|
||||
@@ -3732,6 +3784,11 @@ type GroupSiteOptions implements AcfFieldGroup & AcfFieldGroupFields & GroupSite
|
||||
Field of the "phone" Field Type added to the schema as part of the "GroupSiteOptions" Field Group
|
||||
"""
|
||||
phoneNumber: AcfPhone!
|
||||
|
||||
"""
|
||||
Field of the "repeater" Field Type added to the schema as part of the "GroupAbstractSocial" Field Group
|
||||
"""
|
||||
profiles: [GroupAbstractSocialProfiles]!
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -3763,7 +3820,7 @@ interface GroupSiteOptionsLinks_Fields implements AcfFieldGroup & AcfFieldGroupF
|
||||
"""
|
||||
Interface representing fields of the ACF "GroupSiteOptions" Field Group
|
||||
"""
|
||||
interface GroupSiteOptions_Fields implements AcfFieldGroup & AcfFieldGroupFields {
|
||||
interface GroupSiteOptions_Fields implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractSocial_Fields {
|
||||
"""
|
||||
Field of the "email" Field Type added to the schema as part of the "GroupSiteOptions" Field Group
|
||||
"""
|
||||
@@ -3781,6 +3838,11 @@ interface GroupSiteOptions_Fields implements AcfFieldGroup & AcfFieldGroupFields
|
||||
Field of the "phone" Field Type added to the schema as part of the "GroupSiteOptions" Field Group
|
||||
"""
|
||||
phoneNumber: AcfPhone!
|
||||
|
||||
"""
|
||||
Field of the "repeater" Field Type added to the schema as part of the "GroupAbstractSocial" Field Group
|
||||
"""
|
||||
profiles: [GroupAbstractSocialProfiles]!
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user