From 8358571b2948ed7b258d1a44d9ee060edbedaf43 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Thu, 10 Jun 2021 09:25:29 +0100 Subject: [PATCH] Get a11y lint script paths from rails helper (#13912) * retrieve paths from rails helper * move assets to vendor folder, precompile in assets config * drop coverage on lines * remove unneeded line --- app/javascript/article-form/articleForm.jsx | 15 ++++++++++----- app/views/articles/edit.html.erb | 1 + app/views/articles/new.html.erb | 1 + config/initializers/assets.rb | 1 + jest.config.js | 2 +- .../assets/javascripts/markdown-it.min.js | 0 .../javascripts/markdownlint-browser.min.js | 0 7 files changed, 14 insertions(+), 6 deletions(-) rename {app => vendor}/assets/javascripts/markdown-it.min.js (100%) rename {app => vendor}/assets/javascripts/markdownlint-browser.min.js (100%) diff --git a/app/javascript/article-form/articleForm.jsx b/app/javascript/article-form/articleForm.jsx index dff7b6191..56e522029 100644 --- a/app/javascript/article-form/articleForm.jsx +++ b/app/javascript/article-form/articleForm.jsx @@ -200,17 +200,22 @@ export class ArticleForm extends Component { fetchMarkdownLint = async () => { if (!window.markdownlint) { + const pathDataElement = document.getElementById('markdown-lint-js-path'); + if (!pathDataElement) { + return; + } + + // Retrieve the correct fingerprinted URL for the scripts + const { markdownItJsPath, markdownLintJsPath } = pathDataElement.dataset; + const markdownItScript = document.createElement('script'); - markdownItScript.setAttribute('src', '/assets/markdown-it.min.js'); + markdownItScript.setAttribute('src', markdownItJsPath); document.body.appendChild(markdownItScript); // The markdownlint script needs the first script to have finished loading first markdownItScript.addEventListener('load', () => { const markdownLintScript = document.createElement('script'); - markdownLintScript.setAttribute( - 'src', - '/assets/markdownlint-browser.min.js', - ); + markdownLintScript.setAttribute('src', markdownLintJsPath); document.body.appendChild(markdownLintScript); markdownLintScript.addEventListener('load', this.lintMarkdown); diff --git a/app/views/articles/edit.html.erb b/app/views/articles/edit.html.erb index 84df38d00..75b4c751b 100644 --- a/app/views/articles/edit.html.erb +++ b/app/views/articles/edit.html.erb @@ -31,3 +31,4 @@ <%= render "articles/v2_form", article: @article, organizations: @organizations, version: @version %> <%= javascript_packs_with_chunks_tag "clipboardCopy", "articleForm", defer: true %> +