كيفية السماح بعلامات HTML معينة في التخصيص

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:

مرحبًا @tshenry،

هل يمكنك مساعدتي في الكود الذي استخدمته لبناء GCSE في discourse؟

شكرًا لك

مرحبًا @yyhmsg،

هل يمكنك مساعدتي في تنفيذ GCSE؟

للأسف، لا يمكنني تقديم الكثير من المساعدة لأنني لم أعد أستخدم GCSE. لقد نجح الأمر معي لفترة من الوقت، لكنني انتقلت بعيدًا عن Google بشكل عام وأزلت الإضافة منذ عدة إصدارات من Discourse. ما تم نشره أعلاه كان يعمل، لكنني اضطررت إلى تجربة العديد من التعديلات لحل مشاكل التمرير اللانهائي والتعامل مع التغييرات التي طرأت على Discourse.

ما الذي جربته؟ وما الأخطاء أو المشاكل التي واجهتها؟

قد تكون هناك خيار أنظف وأسهل لا يتطلب الكثير من الإدارة، وهو ببساطة إضافة زر في الأعلى ينقل إلى صفحة بحث مستضافة على Google، أو صفحة خاصة بك في مكان آخر.

@yyhmsg،

لقد قمت بتنفيذ الكود. أجريت بعض التغييرات على CSS لإنشاء مربع بحث. ولكن، عند النقر على خيار البحث، يتم توجيهي افتراضيًا إلى بحث Discourse وليس إلى بحث Google. هنا علق الأمر.

إذا قمت بإعداده ولكنه يوجه إلى أداة بحث خاطئة، فهذا يعني على الأرجح أن معلمة استعلام البحث (query search parameter) تحتاج إلى تغيير بحيث لا يكون كلاهما q=.

queryParameterName (اسم معلمة الاستعلام): اسم معلمة الاستعلام — على سبيل المثال، q (الافتراضي) أو query. سيتم تضمين هذا في عنوان URL (على سبيل المثال، Example Domain).

لذلك، يجب عليك إعداد GCSE لاستخدام اسم معلمة استعلام مختلف، مثل qr=. عندئذٍ، عند تقديم البحث، سيجيب GCSE فقط لأن Discourse يتوقع أن تكون المعلمة q=.

مرحبًا @yyhmsg،

أنا أستخدم سمة Overlay لـ GCSE، وأرغب في عرض نتائج البحث على نفس الصفحة وليس في صفحة مختلفة، حيث لا يمكنني استخدام تنسيق صفحتين مع discourse. ومع ذلك، لا يزال زر البحث يضيف سلسلة الاستعلام “?search=search+term”.

هذا لا يؤدي إلى ظهور أي نتائج بحث، حيث يُظهر الرسالة “لا توجد مواضيع حديثة”.

هل هناك شيء فاتني؟

شكرًا مقدّمًا.

سيكون من المفيد جدًا أن تُظهر الكود الذي تستخدمه، ورابط الموقع الذي تعمل عليه، إذا كان متاحًا.

مرحبًا @yyhmsg،

الموقع الذي أعمل عليه هو: mpl.co
هل يمكننا التواصل عبر Google Meet أو ما شابه ذلك لمشاركة الشاشة؟ الرجاء إخباري بالوقت المناسب لك.

شكرًا لك.

للأسف، لا أستطيع ذلك، فأنا مقدم رعاية صحية ولدي جدول مزدحم، ولا أملك سوى بضع دقائق بين كل مريض والآخر للعمل على أمور كهذه.

هل لي أن أقترح إضافة مثل هذه الإضافة - GitHub - sylque/discpage: A Discourse plugin to create static pages and attach discussions to headings · GitHub - حيث يمكنك وضع كود gcse بالكامل داخل الصفحة، ثم إضافة زر في الرأس يربط بتلك الصفحة. يبدو ذلك حلاً أنيقًا جدًا…

شكرًا لك @yyhmsg، سأحاول من جهتي. شكرًا على اقتراحاتك.