You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ActivityPub plugin uses the WordPress Block Editor (Gutenberg) architecture for developing custom blocks. All block-related code is located in the `/src` directory.
73
+
The ActivityPub plugin uses the WordPress Block Editor (Gutenberg) architecture for developing custom blocks. All block-related code is located in the `/src/blocks` directory.
74
74
75
75
#### Block Structure
76
76
77
77
Each block typically follows this directory structure:
78
78
79
79
```
80
-
/src/block-name/
80
+
/src/blocks/block-name/
81
81
├── block.json # Block configuration.
82
82
├── edit.js # Edit component.
83
83
├── index.js # Block registration.
@@ -93,48 +93,62 @@ Each block typically follows this directory structure:
93
93
4.**Accessibility**: Ensure your blocks are accessible to all users.
94
94
5.**Indentation**: Use tabs for indentation in SCSS files, not spaces.
95
95
96
-
### Standalone Assets
96
+
### Feature-Based Asset Organization
97
97
98
-
For non-block JavaScript and CSS files, the ActivityPub plugin uses the `/src` directory for source files, which are then built into the `/build`directory by `wp-scripts build`.
98
+
The ActivityPub plugin organizes scripts and styles by feature rather than by file type. Each feature has its own directory containing all related assets.
99
99
100
100
#### Structure
101
101
102
102
```
103
103
/src/
104
-
├── css/ # Source CSS files.
105
-
├── js/ # Source JavaScript files.
106
-
└── [block-name]/ # Block directories.
107
-
108
-
/build/
109
-
├── css/ # Built CSS files.
110
-
└── js/ # Built JavaScript files.
104
+
├── blocks/ # Block-specific code and styles
105
+
│ ├── reply/ # Reply block
106
+
│ └── ... # Other blocks
107
+
├── wp-admin/ # Admin-related features
108
+
│ ├── admin.js # Admin JavaScript
109
+
│ ├── admin.scss # Admin styles
110
+
│ └── ... # Other admin features
111
+
├── feature-name/ # Any other feature
112
+
│ ├── script.js # Feature JavaScript
113
+
│ ├── style.scss # Feature styles
114
+
│ └── ... # Other feature files
115
+
└── ... # Other feature directories
116
+
117
+
/build/ # Compiled assets, organized by feature
111
118
```
112
119
113
-
#### Adding New JavaScript Files
120
+
#### Adding New Feature Assets
114
121
115
-
1. Create your JavaScript source file in the `/src/js/` directory:
122
+
1. Create a new directory for your feature in the `/src/` directory:
116
123
```
117
-
/src/js/your-feature.js
124
+
/src/your-feature/
118
125
```
119
126
120
-
2. When you run `npm run build`, WordPress Scripts will:
121
-
- Compile your JavaScript file to `/build/js/your-feature.js`.
122
-
- Generate an asset file at `/build/js/your-feature.asset.php` containing dependencies and version information.
127
+
2. Add your JavaScript and/or SCSS files to this directory:
128
+
```
129
+
/src/your-feature/script.js
130
+
/src/your-feature/style.scss
131
+
```
123
132
124
-
3. Enqueue your script in PHP, using the generated asset file:
133
+
3. When you run `npm run build`, WordPress Scripts will:
134
+
- Compile your JavaScript file to `/build/your-feature/script.js`.
135
+
- Compile and minify your SCSS to `/build/your-feature/style.css`.
136
+
- Generate source maps.
137
+
138
+
4. Enqueue your script and/or stylesheet in PHP, using the generated asset file:
125
139
126
140
```php
127
141
/**
128
142
* Enqueue admin scripts.
129
143
*/
130
144
function activitypub_enqueue_admin_scripts() {
131
145
// Load the asset file to get dependencies and version.
132
-
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/js/your-feature.asset.php';
146
+
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/your-feature/script.asset.php';
133
147
134
148
wp_enqueue_script(
135
149
'activitypub-your-feature',
136
150
plugins_url(
137
-
'build/js/your-feature.js',
151
+
'build/your-feature/script.js',
138
152
ACTIVITYPUB_PLUGIN_FILE
139
153
),
140
154
$asset_data['dependencies'],
@@ -143,28 +157,15 @@ function activitypub_enqueue_admin_scripts() {
0 commit comments