Skip to content

Commit

Permalink
Merge pull request #39 from alleyinteractive/pre-get-posts
Browse files Browse the repository at this point in the history
Switching to use pre_get_posts for archiveless
  • Loading branch information
srtfisher committed Aug 24, 2022
2 parents 3389f2d + 521407d commit b43eeed
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 293 deletions.
45 changes: 3 additions & 42 deletions .github/workflows/built-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,6 @@ on:

jobs:
built-branch:
name: Built Branch
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Clear previous vendor
shell: bash
run: rm -rf vendor
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 8.0
version: 2
args: --prefer-dist --no-dev
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install node dependencies (npm ci)
run: npm install
- name: Run npm build
run: npm run build
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Push to -built branch
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILT_BRANCH: '${{ steps.extract_branch.outputs.branch }}-built'
run: |
git config --global user.email "[email protected]"
git config --global user.name "$GITHUB_ACTOR"
rm -rf .gitignore docker_tag output.log .github
mv .deployignore .gitignore
git checkout -b $BUILT_BRANCH
git add -A && git commit -m "Changes from $GITHUB_SHA"
git push --force -u origin "${BUILT_BRANCH}"
uses: alleyinteractive/.github/.github/workflows/built-branch.yml@main
with:
node: 16
50 changes: 4 additions & 46 deletions .github/workflows/built-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,7 @@ on:
- '!*-built'

jobs:
built-branch:
name: Create Built Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Clear previous vendor
shell: bash
run: rm -rf vendor && rm -rf composer.lock
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 8.0
version: 2
args: --prefer-dist --no-dev
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install node dependencies (npm ci)
run: npm install
- name: Run npm build
run: npm run build
- name: Extract branch name
shell: bash
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
id: vars
- name: Push to -built branch
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILT_BRANCH: '${{ steps.vars.outputs.tag }}-built'
TAG_NAME: '${{ steps.vars.outputs.tag }}-built'
run: |
git config --global user.email "[email protected]"
git config --global user.name "$GITHUB_ACTOR"
rm -rf .gitignore docker_tag output.log .github
mv .deployignore .gitignore
git checkout -b $BUILT_BRANCH
git add -A && git commit -m "Built changes for $TAG_NAME"
git tag -a "$TAG_NAME" -m "Build assets for $TAG_NAME"
git push origin "refs/tags/$TAG_NAME"
built-tag:
uses: alleyinteractive/.github/.github/workflows/built-tag.yml@main
with:
node: 16
42 changes: 2 additions & 40 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,5 @@ on:
- cron: '0 0 * * *'

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.0]
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v3
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ matrix.php }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
tools: composer:v2
coverage: none
- name: Validate Composer
run: composer validate --strict
- name: Install dependencies
uses: nick-invision/[email protected]
with:
timeout_minutes: 5
max_attempts: 5
command: composer install
- name: Run phpcs
run: composer run phpcs
coding-standards:
uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main
29 changes: 5 additions & 24 deletions .github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,8 @@ on:
pull_request:

jobs:
npm-ci:
name: (npm) Install, build, and test
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Cancel previous runs of this workflow (pull requests only)
if: ${{ github.event_name == 'pull_request' }}
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install node dependencies (npm ci)
run: npm install
- name: Run npm lint
run: npm run lint
- name: Run npm build
run: npm run build
node-tests:
uses: alleyinteractive/.github/.github/workflows/node-tests.yml@main
with:
node: 16
run-test: false
82 changes: 6 additions & 76 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,12 @@ on:
- cron: '0 0 * * *'

jobs:
test:
runs-on: ${{ matrix.os }}
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis:5.0
ports:
- 6379:6379
options: --entrypoint redis-server
continue-on-error: ${{ matrix.can_fail }}
php-tests:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0]
wp_version: ["latest"]
can_fail: [false]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
env:
CACHEDIR: /tmp/test-cache
WP_CORE_DIR: /tmp/wordpress
WP_VERSION: ${{ matrix.wp_version }}
WP_DB_HOST: 127.0.0.1
WP_DB_USER: root
WP_DB_PASSWORD: '""'

steps:
- name: Cancel previous runs of this workflow (pull requests only)
if: ${{ github.event_name == 'pull_request' }}
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout code
uses: actions/checkout@v3

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v3
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.lock') }}--
restore-keys: |
${{ runner.os }}-${{ matrix.stability }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
tools: composer:v2
coverage: none

- name: Validate Composer
run: composer validate --strict

- name: Install dependencies
uses: nick-invision/[email protected]
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Test Package
shell: bash
run: composer run phpunit
wordpress: ["latest"]
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
with:
php: ${{ matrix.php }}
wordpress: ${{ matrix.wordpress }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this plugin will be documented in this file.

## 1.0.0

- Initial release
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Archiveless

[![Testing Suite](https://github.com/alleyinteractive/archiveless/actions/workflows/unit-test.yml/badge.svg)](https://github.com/alleyinteractive/archiveless/actions/workflows/unit-test.yml)
[![Testing
Suite](https://github.com/alleyinteractive/archiveless/actions/workflows/unit-test.yml/badge.svg)](https://github.com/alleyinteractive/archiveless/actions/workflows/unit-test.yml)

Hide WordPress posts from archives, which includes the index page, search
results, date archives, author archives, and term lists.
Excludes specific WordPress posts from archives (homepage, search,
date/author/term archives).

Adds `<meta name='robots' content='noindex,nofollow' />` meta to the head to
restrict inclusion in web searches.
Expand All @@ -14,6 +15,37 @@ This plugin provides a way for content to live inside WordPress and still be
accessible by a direct URL but appear hidden everywhere else. Useful for culling
older content that shouldn't appear in search results because it is untimely.

## Usage

By default, the plugin will prevent archiveless posts from appearing on page.
This is limited to the [main
query](https://developer.wordpress.org/reference/functions/is_main_query/) of
the page. It will not affect other queries by default.

Archiveless posts can be excluded from normal queries by passing
`exclude_archiveless`:

```php
// Via get_posts()/WP_Query.
$posts = get_posts(
[
'exclude_archiveless' => true,
'suppress_filters' => false,
// ...
]
);

// Via 'pre_get_posts'.
add_action(
'pre_get_posts',
function ( $query ) {
if ( special_condition() ) {
$query->set( 'exclude_archiveless', true );
}
}
);
```

### Install

The plugin includes uncompiled Javascript. You can install the plugin by
Expand All @@ -25,10 +57,20 @@ npm install
npm run build
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed
recently.

## Maintainers

This project is actively maintained by [Alley
Interactive](https://github.com/alleyinteractive). Like what you see? [Come work
with us](https://alley.co/careers/).

![Alley logo](https://avatars.githubusercontent.com/u/1733454?s=200&v=4)

## License

Licensed under GPL v2.
This software is released under the terms of the GNU General Public License
version 2 or any later version.
Loading

0 comments on commit b43eeed

Please sign in to comment.