構造化データには、
Mezzanine にもJSON-LD
を
参考サイト
schema.orgを
使ってGoogleの 検索結果に サイトリンク検索ボックスを 表示させよう | 海外SEO情報ブログ JSON-LD
の定義に ついて、 参考に なりました。
記事に記載が ありますが、 そもそも アクセス数や、 ページ数が 少ないと、 検索ボックス自体が 出てこないですが、 それは それと して 実装していきます。 Configuration — Mezzanine 4.2.3 documentation
page-menu-templates の説明が 記載されています。 Can you check the internet protocol from Django’s template? - Stack Overflow
django でhttps/http どちらで アクセスしているかを 判定する 方法が 記載されています。
JSON-LD 定義を 記述する ページに ついて
トップページのみ
どのurls.py
に
defalut だと、
以下、urls.py
の
- urls.py
# HOMEPAGE FOR A BLOG-ONLY SITE # ----------------------------- # This pattern points the homepage to the blog post listing page, # and is useful for sites that are primarily blogs. If you use this # pattern, you'll also need to set BLOG_SLUG = "" in your # ``settings.py`` module, and delete the blog page object from the # page tree in the admin if it was installed. url("^$", blog_post_list, name="home"),
通常の
判断に
このPAGE_MENU_TEMPLATES
で
PAGE_MENU_TEMPLATES
の
- デフォルト定義
( (1, 'Top navigation bar', 'pages/menus/dropdown.html'), (2, 'Left-hand tree', 'pages/menus/tree.html'), (3, 'Footer', 'pages/menus/footer.html') )
今回追加先は、pages/menus/dropdown.html
ですので、
追加した 記述
pages/menus/dropdown.html
内に
pages/menus/dropdown.html
{% for page in page_branch %} {% if not has_home and page.is_primary and forloop.first %} <li{% if on_home %} class="active"{% endif %} id="dropdown-menu-home"> <a href="{% url "home" %}">{% trans "Home" %}</a> </li> ####################### // この記述追加 {% if on_home %} <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "WebSite", "url": "{{ request.scheme }}://{{ request.get_host }}", "potentialAction": { "@type": "SearchAction", "target": "{{ request.scheme }}://{{ request.get_host }}{% url "search" %}?q={search_term}" "query-input": "required name=search_term" } } </script> {% endif %} ####################### {% endif %} {% if page.in_menu %} {% endif %}
説明
{{ request.scheme }}://{{ request.get_host }}
{{ request.scheme }}
でhttp/https の ブラウザで アクセスしている プロトコルが、 {{ request.get_host }}
でdomain 名が 取得できます。 1
[1] Django Mezzanine で、複数サイトを 共存させ 同時に 運用する の 状況で 動くかは 試せてないです。 複数サイトの 場合は 動作しないかもしれません。 {% url “search” %}
{% url "search" %}
で、mezzanine の 検索ボックスの URL を 指定しています。 これで サイト内検索時は、 mezzanine の 検索が 使われるようになります。
まとめ
サイト内検索のJSON-LD
に
ただ、
そもそも、
コメント