Skip to content

Instantly share code, notes, and snippets.

View gormus's full-sized avatar
💭
Never be cruel, never be cowardly.

Osman Gormus gormus

💭
Never be cruel, never be cowardly.
View GitHub Profile
@gormus
gormus / fix_wordpress_posts.sql
Created January 8, 2020 21:42
Update WordPress posts which may contain broken code snippets for syntax highlighting.
-- 1. Reset all code snippets to use '<pre><code>' as opening tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '<pre[^>]*>(<code[^>]*>)*', '<pre><code>')
WHERE post_status = 'publish'
AND post_type = 'post'
AND post_content RLIKE '<pre[^>]*>(<code[^>]*>)*';
-- 2. Reset all closing tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '(<\/code>)*<\/pre>>', '</code></pre>')
@gormus
gormus / .js
Created January 25, 2020 00:55
Add `rel="noopener"` to all "A" tags for external links. See https://gist.github.com/gormus/575844 for an old, similar gist
/**
* Add rel="noopener" to all "A" tags for external links.
*
* Selection rules:
* - "A" tag must have "href" attribute, exclude anchors.
* - "href" attribute must not start with a "."
* - "href" attribute must not start with a "/"
* - "A" tag must not have rel="noopener" set.
* - "A" tag must not have rel="noreferrer" set.
*
@gormus
gormus / syntax-highlighting.sh
Created June 25, 2020 06:13
WP CLI search-replace normalize syntax highlighting wrapper markup
#!/usr/bin/env bash
wp search-replace '<pre[^>]*>(<code[^>]*>)*' '<pre><code>' 'wp_posts' \
--regex \
--regex-flags='i' \
--skip-plugins \
--skip-themes \
--skip-packages \
--color \
--include-columns='post_content' \
@gormus
gormus / deploy.sh
Created October 19, 2021 00:24
Drupal Deployment Script for Platform.sh Environments
#!/usr/bin/env bash
#
#
# Drupal Deployment Script for Platform.sh Environments
# ==============================================================================
# Authored by osman gormus <[email protected]> on Oct 5, 2021
#
#
# deploy: |