Come consentire determinati tag HTML nella personalizzazione

I’m trying to add the google custom search engine to the header of our discourse forum. I put in the javascript to the head tag and then in the body there is something like <gcse:search linkTarget="_self"></gcse:search> - which will show the google custom search engine.

When I put this in and save it however, it doesn’t show up on the site. I imagine it is being removed by some sort of html filter? (and I should add that by “doesn’t show up” I mean the code itself, not just that the javascript isn’t loading somehow - when I surround it with <!-- -->, the code passes through, but obviously doesn’t work).

Is there a way to get this to pass through?

Thanks!

Looking at this it apparently strips gcse - so I get:

<search linktarget=\"_self\"><\/search>

Which doesn’t load anything

Instead of <gcse:search linkTarget="_self"></gcse:search> it strips out the : and the /gcse

I tried <gcse\:search><\/gcse\:search> but then I get <gcse search> (no : ) and </gcse> (no : or search)

Is there another way to get a variable to pass through the customization editor so that I can get it to show up?

This is just a proof of concept, so you’ll have to play around with it to see how/if it can work for your needs. Try adding this to the </head> tab of a theme:

<script type="text/discourse-plugin" version="0.8.18">
    api.decorateWidget('header-contents:after', helper => {
        return helper.rawHtml(`<gcse:search linkTarget="_self"></gcse:search>`);
    });
</script>

(Edit: improved the answer a little after having more time to look at it :slightly_smiling_face:)

That’s awesome - Thanks! Works perfectly. Both versions seemed to work the same, but I went with your current edit.

Actually I may have spoke a little too soon… It’s fairly intermittent when it will show up. I had both versions of your script in so I thought this newer one was working (and it did once - minus putting the search bar on top of the menu, etc. - lower half of the header).

The first script appears to work on the front page only if I put in at the body close section - then it shows up at the top of the page oddly.

I’d like to try to get it right below the header bar on top on every page.

Instead of ‘header-contents:after’ - is there a ‘body-contents:before’? that I could try. I went through the api docs, but couldn’t find anything that showed such a declaration…

Sure, if you change it from header-contents:after to just header:after, that should do the trick. You will need to style it with CSS to get it exactly how you want it, but that should get you on track :slightly_smiling_face:

Ciao @tshenry,

Potresti aiutarmi con il codice su come sei riuscito a costruire GCSE in Discourse?

Grazie

Ciao @yyhmsg,

Potresti aiutarmi con l’implementazione di GCSE?

Purtroppo non posso offrire molto aiuto, dato che non uso più GCSE. L’ho fatto funzionare per un po’, ma alla fine mi sono allontanato da Google in generale e l’ho rimosso molte versioni fa di Discourse. Ciò che è stato pubblicato sopra ha funzionato, ma ho dovuto fare parecchi tentativi per risolvere problemi di scorrimento infinito e per adattarmi ai cambiamenti di Discourse.

Cosa hai provato? E quali errori o problemi hai riscontrato?

Un’opzione più pulita e semplice, che non richieda molta manutenzione, potrebbe essere quella di aggiungere semplicemente un pulsante in alto che reindirizzi a una pagina di ricerca ospitata da Google o a qualcosa di tuo ospitato altrove.

@yyhmsg,

Ho implementato il codice. Ho apportato alcune modifiche CSS per creare una casella di ricerca. Tuttavia, quando faccio clic sull’opzione di ricerca, mi reindirizza per impostazione predefinita alla ricerca di Discourse e non a quella di Google. Qui è dove mi sono bloccato.

Se l’hai configurato ma sta reindirizzando allo strumento di ricerca sbagliato, è probabile che il parametro di query debba essere modificato in modo che entrambi non siano “q=”.

queryParameterName String Il nome del parametro di query—ad esempio, q (predefinito) o query. Questo verrà incorporato nell’URL (ad esempio, Example Domain).

Quindi, il tuo GCSE dovrà essere configurato per utilizzare un nome di parametro di query diverso, come “qr=”; così, quando invii una ricerca, solo il GCSE risponderà, poiché Discourse si aspetta “q=”.

Ciao @yyhmsg,

sto utilizzando il tema Overlay per GCSE e vorrei visualizzare i risultati della ricerca nella stessa pagina, non in una pagina diversa, poiché non posso utilizzare il formato a due pagine con Discourse. Tuttavia, il pulsante di ricerca continua ad aggiungere la stringa di query “?search=search+term”.

Questo non genera alcun risultato di ricerca e viene visualizzato il messaggio “Nessun argomento recente”.

Manca qualcosa nel mio setup?

Grazie in anticipo.

Sarebbe molto utile se mostraste il codice che state utilizzando e, se disponibile, un link al sito su cui state lavorando.

Ciao @yyhmsg,

Il sito web su cui sto lavorando è: mpl.co
Possiamo collegarci su Google Meet o qualcosa di simile per condividere lo schermo. Fammi sapere, il tuo orario comodo.

Grazie.

Purtroppo non posso, sono un operatore sanitario con un programma molto impegnativo; ho solo pochi minuti tra un paziente e l’altro per dedicarmi a cose del genere.

Potrei suggerire qualcosa come questo plugin - GitHub - sylque/discpage: A Discourse plugin to create static pages and attach discussions to headings · GitHub - dove potresti inserire l’intero codice GCSE nella pagina e poi aggiungere semplicemente un pulsante nell’intestazione che collega a quella pagina. Sembra una soluzione piuttosto pulita…

Grazie @yyhmsg, proverò dalla mia parte. Grazie per i tuoi suggerimenti.