diff --git a/poetry.lock b/poetry.lock index 6eaf9aeac..4fd2870f6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. [[package]] name = "aldryn-apphooks-config" @@ -135,6 +135,29 @@ files = [ pycodestyle = ">=2.6.0" toml = "*" +[[package]] +name = "beautifulsoup4" +version = "4.13.4" +description = "Screen-scraping library" +optional = false +python-versions = ">=3.7.0" +groups = ["main"] +files = [ + {file = "beautifulsoup4-4.13.4-py3-none-any.whl", hash = "sha256:9bbbb14bfde9d79f38b8cd5f8c7c85f4b8f2523190ebed90e950a8dea4cb1c4b"}, + {file = "beautifulsoup4-4.13.4.tar.gz", hash = "sha256:dbb3c4e1ceae6aefebdaf2423247260cd062430a410e38c66f2baa50a8437195"}, +] + +[package.dependencies] +soupsieve = ">1.2" +typing-extensions = ">=4.0.0" + +[package.extras] +cchardet = ["cchardet"] +chardet = ["chardet"] +charset-normalizer = ["charset-normalizer"] +html5lib = ["html5lib"] +lxml = ["lxml"] + [[package]] name = "certifi" version = "2020.6.20" @@ -950,6 +973,28 @@ url = "https://github.com/TACC/Core-CMS-Plugin-Image-Gallery.git" reference = "v0.1.4" resolved_reference = "5d93622cae3ecbffc9599c2aed140c2a06983768" +[[package]] +name = "djangocms-tacc-remote-content" +version = "0.1.0" +description = "A DjangoCMS plugin (for TACC Core CMS) to fetch and display content from remote TACC URLs." +optional = false +python-versions = "*" +groups = ["main"] +files = [] +develop = false + +[package.dependencies] +beautifulsoup4 = ">=4.9.3" +Django = ">=3.2" +django-cms = ">=3.7.4,<4" +requests = ">=2.25.1" + +[package.source] +type = "git" +url = "https://github.com/TACC/Core-CMS-Plugin-Remote-Content.git" +reference = "v0.3.3" +resolved_reference = "dfdd8f5cf65efff3bb4a9d1c26e51fad57535a25" + [[package]] name = "djangocms-tacc-system-monitor" version = "0.3.0" @@ -2128,6 +2173,18 @@ files = [ {file = "snowballstemmer-2.0.0.tar.gz", hash = "sha256:df3bac3df4c2c01363f3dd2cfa78cce2840a79b9f1c2d2de9ce8d31683992f52"}, ] +[[package]] +name = "soupsieve" +version = "2.7" +description = "A modern CSS selector implementation for Beautiful Soup." +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "soupsieve-2.7-py3-none-any.whl", hash = "sha256:6e60cc5c1ffaf1cebcc12e8188320b72071e922c2e897f737cadce79ad5d30c4"}, + {file = "soupsieve-2.7.tar.gz", hash = "sha256:ad282f9b6926286d2ead4750552c8a6142bc4c783fd66b0293547c8fe6ae126a"}, +] + [[package]] name = "sqlparse" version = "0.3.1" @@ -2445,4 +2502,4 @@ testing = ["func-timeout", "jaraco.itertools"] [metadata] lock-version = "2.1" python-versions = ">=3.11,<4.0" -content-hash = "766c68cb84867dcdaeaf2ef18ee43ad304b1297efdfe5252a7cdece3ad7e3b2e" +content-hash = "077910c85e2fda3f3ff38d22d4275d876d2ecef54cd3e21ed2ee744c56771495" diff --git a/pyproject.toml b/pyproject.toml index a4aaf6378..12896b273 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ djangocms-picture = "3.0.0" djangocms-snippet = "3.0.0" djangocms-style = "3.0.0" djangocms-tacc-image-gallery = {git = "https://github.com/TACC/Core-CMS-Plugin-Image-Gallery.git", rev = "v0.1.4"} +djangocms-tacc-remote-content = {git = "https://github.com/TACC/Core-CMS-Plugin-Remote-Content.git", rev = "v0.3.3"} djangocms-tacc-system-monitor = {git = "https://github.com/TACC/Core-CMS-Plugin-System-Monitor.git", rev = "v0.3.0"} djangocms-text-ckeditor = "^5.1" djangocms-transfer = "1.0.1" diff --git a/taccsite_cms/settings_custom.example.py b/taccsite_cms/settings_custom.example.py index 2cf2acce9..fb8177a6c 100644 --- a/taccsite_cms/settings_custom.example.py +++ b/taccsite_cms/settings_custom.example.py @@ -33,8 +33,8 @@ ('standard.html', 'Standard'), ('fullwidth.html', 'Full Width'), - # WARNING: Not intuitive to unset, so only enable as needed e.g. serve Blog such that it can be injected into another CMS - # ('raw.html', 'Raw'), + # WARNING: Unintuitive, so only enable as needed e.g. TACC/Core-CMS#868 + # ('plain.html', 'Plain'), ) ######################## diff --git a/taccsite_cms/static/site_cms/js/modules/manageExternalArticles.js b/taccsite_cms/static/site_cms/js/modules/manageExternalArticles.js new file mode 100644 index 000000000..bd73e0c0e --- /dev/null +++ b/taccsite_cms/static/site_cms/js/modules/manageExternalArticles.js @@ -0,0 +1,46 @@ +/** + * Get URL of external web article of which internal news article represents + * @param {HTMLElement} article - The article within which to find external URL + * @return {string|null} - The URL of the external article + */ +export function getArticleExternalURL(article) { + if (!article) { + console.warn('No article found', article); + return; + } + + // The admin of news promises leads/abstracts will only have 1 external link + const contentLink = article.querySelector('.blog-lead a[href^="http"]'); + const isExternalLink = contentLink.hostname !== window.location.hostname; + const URL = isExternalLink ? contentLink.href : null; + + return URL; +} + +/** + * Modify article links to point to external URLs based on tag name + * @param {string} [extTagName='external'] - A tag that has been set on articles to select + */ +export function changeHowExternalArticleOpens(extTagName = 'external') { + const articles = document.querySelectorAll( + `.blog-list article.has-blog-tag-${extTagName}` + ); + + console.debug(`Found ${articles.length} article(s) with tag "${extTagName}"`, articles ); + + [ ...articles ].forEach( article => { + const externalLinkUrl = getArticleExternalURL( article ); + + if ( externalLinkUrl ) { + const links = article.querySelectorAll(':is(h3, footer) a'); + + // all links to the post should open external URL in new window + [ ...links ].forEach( link => { + console.debug(`Changed article link to "${externalLinkUrl}"`, link ); + + link.href = externalLinkUrl; + link.setAttribute('target', '_blank'); + }); + } + }); +} diff --git a/taccsite_cms/templates/raw.html b/taccsite_cms/templates/plain.html similarity index 100% rename from taccsite_cms/templates/raw.html rename to taccsite_cms/templates/plain.html diff --git a/taccsite_cms/templates/snippets/news/open-external-articles.html b/taccsite_cms/templates/snippets/news/open-external-articles.html new file mode 100644 index 000000000..99dbafa6d --- /dev/null +++ b/taccsite_cms/templates/snippets/news/open-external-articles.html @@ -0,0 +1,16 @@ +{# To open external news article, instead of internal news article #} +{% load static %} + +