Skip to content

Commit

Permalink
Merge pull request #220 from ma10/add-copy-link-button-20240405
Browse files Browse the repository at this point in the history
ガイドライン項目やチェック内容の見出しにリンクをコピーするボタンを追加
  • Loading branch information
ma10 authored Apr 9, 2024
2 parents cdb967d + 9892657 commit a55e9aa
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 3 deletions.
15 changes: 15 additions & 0 deletions en/source/_static/a11y-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ body {
border: 1px solid #ccc;
padding: 16px;
}

button.copy-link{
margin-left: 0.5em;
cursor: pointer;
border: 0;
font-size: 1rem;
background: transparent;
color: #2779B0;
padding: 0;
height: 1.5rem;
}

button.copy-link:hover {
color: #236D9F;
}
17 changes: 17 additions & 0 deletions en/source/_static/copylink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.addEventListener('DOMContentLoaded', function () {
const buttonLabel = 'Copy Link';
const sections = document.querySelectorAll('section.permalink');

sections.forEach(section => {
const header = section.querySelector('h2');
if (header) {
const button = document.createElement('button');
button.textContent = buttonLabel;
button.className = 'copy-link';
button.onclick = function () {
navigator.clipboard.writeText(location.origin + location.pathname + '#' + section.id);
};
header.appendChild(button);
}
});
});
1 change: 1 addition & 0 deletions en/source/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<meta property="og:url" content="{{ theme_canonical_url }}{{ pagename }}{{ file_suffix }}" />
<meta name="twitter:card" content="summary_large_image" />
{% endif %}
<script src="{{ pathto('_static/copylink.js', 1) }}"></script>
{% endblock %}
{% block content %}
<p><a href="{{ baseurl_ja }}{{ pagename }}.html">The normative (Japanese) version of this page is here.</a></p>
Expand Down
15 changes: 15 additions & 0 deletions ja/source/_static/a11y-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ body {
border: 1px solid #ccc;
padding: 16px;
}

button.copy-link{
margin-left: 0.5em;
cursor: pointer;
border: 0;
font-size: 1rem;
background: transparent;
color: #2779B0;
padding: 0;
height: 1.5rem;
}

button.copy-link:hover {
color: #236D9F;
}
17 changes: 17 additions & 0 deletions ja/source/_static/copylink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.addEventListener('DOMContentLoaded', function () {
const buttonLabel = 'リンクをコピー';
const sections = document.querySelectorAll('section.permalink');

sections.forEach(section => {
const header = section.querySelector('h2');
if (header) {
const button = document.createElement('button');
button.textContent = buttonLabel;
button.className = 'copy-link';
button.onclick = function () {
navigator.clipboard.writeText(location.origin + location.pathname + '#' + section.id);
};
header.appendChild(button);
}
});
});
1 change: 1 addition & 0 deletions ja/source/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<meta property="og:url" content="{{ theme_canonical_url }}{{ pagename }}{{ file_suffix }}" />
<meta name="twitter:card" content="summary_large_image" />
{% endif %}
<script src="{{ pathto('_static/copylink.js', 1) }}"></script>
{% endblock %}
{% block content %}
{% if meta is defined %}
Expand Down
2 changes: 1 addition & 1 deletion tools/yaml2rst/templates/checks/allchecks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% for check in allchecks -%}
.. _check-{{ check.id }}:

{% filter make_heading(2) -%}
{% filter make_heading(2, 'permalink') -%}
{%- if lang == 'ja' -%}
チェックID:{{ check.id }}
{%- elif lang == 'en' -%}
Expand Down
2 changes: 1 addition & 1 deletion tools/yaml2rst/templates/checks/examples-tool.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% for ex in examples -%}
.. _check-example-{{ ex.tool }}-{{ ex.check_id }}:

{% filter make_heading(2) -%}
{% filter make_heading(2, 'permalink') -%}
:ref:`check-{{ ex.check_id }}`
{%- endfilter %}

Expand Down
2 changes: 1 addition & 1 deletion tools/yaml2rst/templates/gl-category.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% for gl in guidelines -%}
.. _{{ gl.id }}:

{{ gl.title|make_heading(2) }}
{{ gl.title|make_heading(2, 'permalink') }}

{{ gl.guideline }}

Expand Down

0 comments on commit a55e9aa

Please sign in to comment.